Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.json
!defaults.json
4 changes: 4 additions & 0 deletions config/defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"port": 3000,
"client": []
}
12 changes: 12 additions & 0 deletions lib/config/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const config = require('.')
const client = {}

config.client.forEach(function (key) {
if (!config.hasOwnProperty(key)) {
throw new Error('Config key "' + key + '" non existent.')
}

client[key] = config[key]
})

module.exports = client
1 change: 1 addition & 0 deletions lib/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = window.config
6 changes: 6 additions & 0 deletions lib/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const path = require('path')
const democracyosConfig = require('democracyos-config')

module.exports = democracyosConfig({
path: path.join(__dirname, '..', '..', 'config')
})
14 changes: 11 additions & 3 deletions lib/server/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const path = require('path')
const express = require('express')
const app = express()
const cookieParser = require('cookie-parser')
const config = require('../config')
const clientConfig = require('../config/client')

const app = express()

// Initialize database models
require('./models')(app)
Expand Down Expand Up @@ -33,8 +36,13 @@ app.use(require('webpack-hot-middleware')(compiler))

app.use('/api', require('./api/apps'))

const clientConfigJson = JSON.stringify(clientConfig)

app.get('/', language, initialState(db), (req, res) => {
res.render('home', { initialState: JSON.stringify(req.store.getState()) })
res.render('home', {
initialState: JSON.stringify(req.store.getState()),
clientConfig: clientConfigJson
})
})

app.listen(3000)
app.listen(config.port)
1 change: 1 addition & 0 deletions lib/server/templates/home.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ html
#react-root=reactOutput
script(type="text/javascript").
window.__INITIAL_STATE__ = !{initialState}
window.config = !{clientConfig}

script(type="text/javascript", src="/dist/vendors.js")
script(type="text/javascript", src="/dist/home.js")
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@
"type-component": "0.0.1",
"webpack": "1.14.0"
},
"scripts": {
"start": "node .",
"debug": "node debug ./lib/server",
"build": "webpack -p --colors --config webpack.config.babel.js",
"lint": "eslint ."
},
"devDependencies": {
"babel-eslint": "^7.1.1",
"eslint": "3.14.0",
Expand All @@ -88,5 +82,14 @@
"react-transform-hmr": "^1.0.4",
"webpack-dev-middleware": "1.9.0",
"webpack-hot-middleware": "2.15.0"
},
"browser": {
"lib/config": "lib/config/config"
},
"scripts": {
"start": "node .",
"debug": "node debug ./lib/server",
"build": "webpack -p --colors --config webpack.config.babel.js",
"lint": "eslint ."
}
}