Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
recidive committed Sep 28, 2016
0 parents commit e168a1b
Show file tree
Hide file tree
Showing 16 changed files with 438 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"babel-polyfill",
"es2015",
"stage-0"
],
"plugins": ["transform-runtime"]
}
74 changes: 74 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Node specific #
#################
# Ignore node modules.
/node_modules

# Webpack #
###########
/dist

# Packages #
############
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.svn

# Logs and databases #
######################
provision/seeds/local/*

# OS generated files #
######################
.DS_Store*
*.Trash*
ehthumbs.db
Icon?
Thumbs.db
*.orig
*.swo
*cwatch.pid

# Editors generated files #
###########################
.project
.settings
*~
*.sublime-project
*.sublime-workspace
*.sublime-projectcompletions
.Drupal.sublime-projectcomplections
nbproject
.buildpath
.sass-cache
.idea
.idea/*
*.log

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Vagrant #
###########
.vagrant
.vagrant/*

# Supervisor #
##############
supervisord.log
supervisord.pid

# Local files #
###############
conf.local.js
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
src
test
dist/test.js
dist/test.js.*
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
node_js:
- '5'
deploy:
provider: npm
email: [email protected]
api_key:
secure: Tg09+e0/z4P0NcVWeN3r4F5DmFGyYC/Z6fNYJTVXgvIEXyBwrzBmj+WjlWUdTpPSaKW9qWle0tVbcC35UAueV02sxelNrRxaN1W0Afelb9L8tTfs6v1TvbhQPw57x+Z7NyX7bBOezvLJOmsnG8pX8W6Wu4r3HZBU8lRlQtEvVZ6IC6GpA5ytzTdRs4W89caqxOWz/QjEqp8Bj43XChUy8w+/g0apukRtm01NHfJbAe7qHztqduaN2IlojhtyI6OKb43opNOZQWcR2wqgCPGVEhdR5lOZ69FgOV7D0t6iRH8W0f1fF7KT59xK8eVtOdCC7Gi52/axGQ12IwhqY6M8xgSA+7jWXXj0/LV52q51IDf1SUVNsEQP5sxkGFJWorquzK4hw6LWRdTna+wBVlma+vujYPKohloPK6etgvnSTwI7+87KWnI3vSJ1heHuSt8r4wcms2t015td30du5LZexzyWgvlF8GwS63AO4/QccVFbNAyJF+6/K8FqeaztXHBeUYgEXL+bKMDmuJLmWjZRO7SWXaK31GBfzzhZyP7qFn0zbJva3pbBZ99HklpvzHJeUjgQAOV08ibLbMfYIUHsnMc5f3i0gCp79efZ+1OzoVc/Y+qSM15Fkqyzx3Uowpj7vYnTn4cZG/GPaHT22fhBmVJg3ELB8ncOpZAR4dQev8E=
on:
tags: true
repo: choko-org/redux-boot-rest
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015-present Sebastian Ferrari, Henrique Recidive, Joseph Ramos

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Redux Boot modules's boilerplate.

[![Build Status](https://travis-ci.org/choko-org/redux-boot-module-boilerplate.svg?branch=master)](https://travis-ci.org/choko-org/redux-boot-module-boilerplate)

Redux Boot module's boilerplate.

## Install
```bash
npm install redux-boot-module-boilerplate --save
```

## Actions constants

```js
import {
HELLO_WORLD
} from 'redux-boot-module-boilerplate'
```

## Usage

```js
// @TODO: Insert how to use.
```

## License

[MIT](LICENSE.md)
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "redux-boot-rest",
"version": "1.0.0",
"description": "Redux Boot based REST server.",
"main": "dist/index.js",
"scripts": {
"start": "npm run build && node dist/index.js",
"build": "rm -f dist/index.js* && webpack",
"pretest": "rm -f dist/test.js* && webpack --config ./webpack.config.test.js",
"test": "tape dist/test.js | tap-spec",
"prepublish": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/choko-org/redux-boot-rest.git"
},
"keywords": [
"redux-boot",
"redux",
"rest"
],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/choko-org/redux-boot-rest/issues"
},
"homepage": "https://github.com/choko-org/redux-boot-rest#readme",
"devDependencies": {
"babel-loader": "^6.2.4",
"babel-plugin-transform-runtime": "^6.6.0",
"babel-polyfill": "^6.7.2",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.5.0",
"babel-runtime": "^6.6.1",
"supertest": "^1.2.0",
"tap-spec": "^4.1.1",
"tape": "^4.5.1",
"webpack": "^1.12.14"
},
"dependencies": {
"redux-boot-webserver": "^1.0.4"
}
}
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const HTTP_BOOT = 'redux-boot/module-boilerplate/http-boot'
export const HTTP_AFTER_BOOT = 'redux-boot/module-boilerplate/http-after-boot'
export const HTTP_REQUEST = 'redux-boot/module-boilerplate/http-request'
19 changes: 19 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import boot from 'redux-boot'
import webserver, { HTTP_REQUEST } from 'redux-boot-webserver'
import rest from './modules/rest'
import storage from './modules/storage'

const initialState = {
variables: { port: 3020 }
}

const modules = [
webserver,
storage,
rest
]

const app = boot(initialState, modules)
.then(({store, action}) => {
console.log('Your server is online!')
})
12 changes: 12 additions & 0 deletions src/modules/rest/actions/getData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const GET_DATA = 'redux/getdata'

const getData = () => {
return ({ db }) => ({
type: GET_DATA,
payload: {
db
}
})
}

export default getData
26 changes: 26 additions & 0 deletions src/modules/rest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { HTTP_REQUEST } from 'redux-boot-webserver'

import getData from './actions/getData'

export default {

middleware: {

[HTTP_REQUEST]: store => next => action => {
const nextResult = next(action)
const { payload: { db } } = store.dispatch(getData())
const { response } = action.payload

db.push(db.length)

response.statusCode = 200
response.setHeader('Content-Type', 'text/plain')

response.end(JSON.stringify(db))

return nextResult
}

}

}
34 changes: 34 additions & 0 deletions src/modules/storage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { HTTP_REQUEST } from 'redux-boot-webserver'

export default {

services: services => next => {
const db = []

const servicesResult = next({
...services,
db
})

return servicesResult
},

enhancer: createStore => (reducer, initialState, enhancer) => {
const store = createStore(reducer, initialState, enhancer)
const db = []

const dispatch = action => {
if (typeof action === 'function') {
return store.dispatch(action({ db }))
}

return store.dispatch(action)
}

return {
...store,
dispatch
}
}

}
40 changes: 40 additions & 0 deletions test/bootstrap.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import test from 'tape'
import {BOOT} from 'redux-boot'
import request from 'supertest'
import boilerplateModule from '../src'
import {HTTP_AFTER_BOOT} from '../src/constants'

test('Web server bootstrap', assert => {
const getState = () => {
return {
variables: { port: 3020 }
}
}

const dispatch = (action) => {

if (action.type === HTTP_AFTER_BOOT) {
const { httpServer } = action.payload

request(httpServer)
.get('/')
.expect(200)
.end((error, response) => {
if (error) throw error

assert.ok(!error, 'Ok')
assert.equal(response.text, 'Hello World!')
assert.end()

httpServer.close()
})
}

return Promise.resolve()
}

const next = action => action
const action = { type: BOOT }

boilerplateModule.middleware[BOOT]({getState, dispatch})(next)(action)
})
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './bootstrap.test'
56 changes: 56 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');

var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});

module.exports = {

debug: false,

entry: {
index: './src/index.js',
},

node: {
__dirname: true,
__filename: true,
},

target: 'node',

devtool: 'source-map',

output: {
path: './dist',
filename: '[name].js',
libraryTarget: 'commonjs2'
},

resolve: {
modulesDirectories: [
'node_modules',
'src'
]
},

module: {
loaders: [{
test: /\.js$/,
include: [
path.resolve(__dirname, './src')
],
exclude: /node_modules/,
loader: 'babel'
}]
},

externals: nodeModules,
}
Loading

0 comments on commit e168a1b

Please sign in to comment.