server: Add basic boiler plating

master
Jonatan Nilsson 2016-01-26 19:12:49 +00:00
parent 869e41ea10
commit e6d966bead
7 changed files with 173 additions and 0 deletions

7
.babelrc Normal file
View File

@ -0,0 +1,7 @@
{
"presets": ["es2015-node5"],
"plugins": [
"syntax-async-generators",
"transform-async-to-generator"
]
}

34
.jshintrc Normal file
View File

@ -0,0 +1,34 @@
{
"eqeqeq": true,
"forin": true,
"immed": true,
"newcap": true,
"noarg": true,
"esnext": true,
"noempty": true,
"nonew": true,
"undef": true,
"unused": "vars",
"strict": true,
"trailing": true,
"noyield": true,
"indent": 2,
"module": true,
"quotmark": "single",
"maxdepth": 4,
"boss": true,
"eqnull": true,
"esversion": 6,
"globalstrict": true,
"smarttabs": true,
"browser": true,
"node": true,
"predef": [
"describe",
"it",
"before",
"beforeEach",
"after",
"afterEach"
]
}

0
dist/.gitkeep vendored Normal file
View File

2
index.js Normal file
View File

@ -0,0 +1,2 @@
require('babel-register');
require('./server');

36
package.json Normal file
View File

@ -0,0 +1,36 @@
{
"name": "nfp_moe",
"version": "1.0.0",
"description": "NFP Moe website",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/nfp-projects/nfp_moe.git"
},
"author": "Jonatan Nilsson",
"license": "WTFPL",
"bugs": {
"url": "https://github.com/nfp-projects/nfp_moe/issues"
},
"homepage": "https://github.com/nfp-projects/nfp_moe",
"dependencies": {
"babel-plugin-syntax-async-generators": "^6.3.13",
"babel-plugin-transform-async-to-generator": "^6.4.6",
"babel-preset-es2015-node5": "^1.1.2",
"babel-register": "^6.4.3",
"bunyan": "^1.5.1",
"koa": "^2.0.0-alpha.3",
"koa-router": "^7.0.1",
"lodash": "^4.0.1",
"nconf": "^0.8.2"
},
"devDependencies": {
"nodemon": "^1.8.1"
}
}

83
server/config.js Normal file
View File

@ -0,0 +1,83 @@
import _ from 'lodash';
import nconf from 'nconf';
// Config follow the following priority check order:
// 1. Arguments
// 2. package.json
// 3. Enviroment variables
// 4. config/config.json
// 5. default settings
//Load arguments as highest priority
nconf.argv();
//Load package.json for name and such
var pckg = require('./package.json');
pckg = _.pick(pckg, ['name','version','description','author','license','homepage']);
//If we have global.it, there's a huge chance
//we're in test mode so we force node_env to be test.
if (typeof global.it === 'function') {
pckg.NODE_ENV = 'test';
}
//Load overrides as second priority
nconf.overrides(pckg);
//Load enviroment variables as third priority
nconf.env();
//Load any overrides from the appropriate config file
if (nconf.get('NODE_ENV') === 'test') {
//Load the config test file if we're in test mode
nconf.file('../config/config.test.json');
}
else {
//Otherwise load from config.json if it exists.
nconf.file('../config/config.json');
}
//Default variables for required database and other settings.
nconf.defaults({
NODE_ENV: 'development',
server: {
port: 3000,
host: '0.0.0.0',
url: 'http://localhost:3000'
},
frontend: {
url: 'http://localhost:3000'
},
bunyan: {
name: pckg.name,
streams: [{
stream: 'process.stdout',
level: 'debug'
}
]
},
jwt: {
secret: 'this-is-my-secret',
options: {
expiresIn: 60 * 24 * 7 * 60 //7 days
}
},
bcrypt: 5
});
module.exports = nconf;

11
server/index.js Normal file
View File

@ -0,0 +1,11 @@
import Koa from 'koa';
const app = new Koa();
// response
app.use(async (ctx) => {
ctx.body = 'Hello World';
});
app.listen(3000, () => console.log('server started 3000'));
export default app;