git ssb

1+

dinoworm ๐Ÿ› / catstack



Commit e077e8e4d717d2c79b41f7287c20906ac86841db

restructure the server stack, boil some more plates

Michael Williams committed on 11/28/2015, 9:16:51 AM
Parent: 0a19ff71e90207bdc5e6b22d5470c11617f9f7b0

Files changed

app/client.jschanged
app/containers/root.jschanged
app/containers/no-match.jsadded
app/routes.jschanged
app/server.jschanged
app/services/static.jsdeleted
app/store.jschanged
app/assets/index.htmladded
app/stack/index.jsadded
app/stack/services.jsadded
app/stack/static.jsadded
config/defaults.jschanged
package.jsonchanged
server.jschanged
app/client.jsView
@@ -15,9 +15,8 @@
1515 )
1616
1717 //store.dispatch(getAllTodos())
1818
19-const main = document.createElement('main')
20-
21-document.body.appendChild(main)
22-
23-render(<Root />, main)
19+render(
20+ <Root />,
21+ document.querySelector('main')
22+)
app/containers/root.jsView
@@ -4,9 +4,9 @@
44
55 const routes = require('app/routes')
66
77 if (process.env.NODE_ENV === 'development') {
8- const DevTools = require('app/containers/dev-tools')
8+ var DevTools = require('app/containers/dev-tools')
99 }
1010
1111 class Root extends React.Component {
1212 render() {
app/containers/no-match.jsView
@@ -1,0 +1,15 @@
1+const React = require('react')
2+const { connect } = require('react-redux')
3+
4+class NoMatch extends React.Component {
5+ render () {
6+ return <div>
7+ no match!
8+ </div>
9+ }
10+}
11+
12+module.exports = connect(
13+ NoMatch,
14+ (state) => { return {} }
15+)
app/routes.jsView
@@ -1,12 +1,15 @@
1+const React = require('react')
12 const { Route } = require('react-router')
23
34 const App = require('app/containers/app')
45 const TodoList = require('app/containers/todo-list')
6+const NoMatch = require('app/containers/no-match')
57
68 const routes = (
79 <Route path='/' component={App}>
810 <Route path='todos' component={TodoList} />
11+ <Route path="*" component={NoMatch} />
912 </Route>
1013 )
1114
1215 module.exports = routes
app/server.jsView
@@ -1,29 +1,13 @@
1-const feathers = require('feathers')
21 const { mapObjIndexed, reduce, toPairs } = require('ramda')
32
4-const serviceCreators = require('./services')
3+const createStack = require('app/stack')
54
65 module.exports = createServer
76
8-const useAll = function (app, services) {
9- return reduce((app, [name, service]) => {
10- return app.use(`/${name}`, service)
11- }, app, toPairs(services))
12-}
13-
147 function createServer (config) {
8+ const server = createStack(config)
159
16- const services = mapObjIndexed(
17- (serviceCreator, name) => {
18- return serviceCreator(config.services[name])
19- },
20- serviceCreators
21- )
10+ server.listen(config.port)
2211
23- const server = feathers()
24-
25- useAll(server, services)
26-
2712 return server
2813 }
29-
app/services/static.jsView
@@ -1,8 +1,0 @@
1-const serveStatic = require('serve-static')
2-const { join } = require('path')
3-
4-module.exports = createStaticService
5-
6-function createStaticService (config) {
7- return serveStatic(config.root, config)
8-}
app/store.jsView
@@ -12,15 +12,17 @@
1212
1313 middleware.push(thunk)
1414
1515 if (process.env.NODE_ENV === 'development') {
16- const { persistState } = require('redux-devtools')
16+ var { persistState } = require('redux-devtools')
17+
18+ var DevTools = require('app/containers/dev-tools')
1719
1820 middleware.push(logger())
1921 }
2022
2123 storesEnhancers.push(
22- applyMiddleware(middleware)
24+ applyMiddleware(...middleware)
2325 )
2426
2527 if (process.env.NODE_ENV === 'development') {
2628 storesEnhancers.push(DevTools.instrument())
app/assets/index.htmlView
@@ -1,0 +1,12 @@
1+<!DOCTYPE html>
2+<html lang="en">
3+ <head>
4+ <meta charset="utf-8" />
5+ <title>Production TodoMVC</title>
6+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7+ </head>
8+ <body>
9+ <main></main>
10+ <script src="bundle.js"></script>
11+ </body>
12+</html>
app/stack/index.jsView
@@ -1,0 +1,35 @@
1+const feathers = require('feathers')
2+const { mapObjIndexed, reduce, toPairs } = require('ramda')
3+
4+const stackCreators = {
5+ services: require('./services'),
6+ static: require('./static')
7+}
8+
9+module.exports = createStack
10+
11+function createStack(config) {
12+ const stacks = createStacks(config)
13+
14+ const app = feathers()
15+
16+ useAll(app, stacks)
17+
18+ return app
19+}
20+
21+function createStacks (config) {
22+ return mapObjIndexed(
23+ (stackCreator, name) => {
24+ return stackCreator(config[name])
25+ },
26+ stackCreators
27+ )
28+}
29+
30+function useAll (app, services) {
31+ return reduce((app, [name, service]) => {
32+ return app.use(service)
33+ }, app, toPairs(services))
34+}
35+
app/stack/services.jsView
@@ -1,0 +1,21 @@
1+const feathers = require('feathers')
2+const { mapObjIndexed, reduce, toPairs } = require('ramda')
3+
4+const services = require('app/services')
5+
6+module.exports = createServices
7+
8+function createServices(config) {
9+ const app = feathers()
10+
11+ useAll(app, services)
12+
13+ return app
14+}
15+
16+function useAll (app, services) {
17+ return reduce((app, [name, service]) => {
18+ return app.use(`/${name}`, service)
19+ }, app, toPairs(services))
20+}
21+
app/stack/static.jsView
@@ -1,0 +1,8 @@
1+const serveStatic = require('serve-static')
2+const { join } = require('path')
3+
4+module.exports = createStatic
5+
6+function createStatic (config) {
7+ return serveStatic(config.root, config)
8+}
config/defaults.jsView
@@ -1,9 +1,10 @@
11 const { join } = require('path')
2+const env = process.env
3+const nodeEnv = env.NODE_ENV
24
35 module.exports = {
4- services: {
5- static: {
6- root: join(__dirname, 'assets')
7- }
8- }
6+ static: {
7+ root: join(__dirname, '..', 'assets')
8+ },
9+ port: env.PORT || 5000
910 }
package.jsonView
@@ -10,10 +10,12 @@
1010 "test": "(npm run spec & npm run feature)",
1111 "spec": "node spec",
1212 "feature": "node feature",
1313 "dev:client": "watchify client -o assets/bundle.js -dv -p browserify-hmr",
14+ "dev:assets": "cpx \"app/assets/**/*\" assets -w",
1415 "dev:server": "nodemon server",
1516 "prod:client": "browserify client -o assets/bundle.js -g uglifyify",
17+ "prod:assets": "cpx \"app/assets/**/*\" assets",
1618 "prod:server": "node server",
1719 "dev": "NODE_ENV=development npm-run-all -p dev:*",
1820 "prod": "NODE_ENV=production npm-run-all -s prod:*"
1921 },
@@ -65,8 +67,9 @@
6567 "babelify": "^7.2.0",
6668 "browserify": "^12.0.1",
6769 "bulk-require": "^0.2.1",
6870 "bulkify": "^1.1.1",
71+ "cpx": "^1.2.1",
6972 "envify": "^3.4.0",
7073 "evalify": "^1.0.1",
7174 "feathers": "^1.2.0",
7275 "history": "^1.13.1",
server.jsView
@@ -2,7 +2,5 @@
22
33 const createServer = require('app/server')
44 const config = require('app/config')
55
6-const server = createServer(config)
7-
8-server.listen(process.env.PORT || 5000)
6+createServer(config)

Built with git-ssb-web