diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..d4f4c84 --- /dev/null +++ b/.babelrc @@ -0,0 +1,7 @@ +{ + "presets": ["es2015-node5"], + "plugins": [ + "syntax-async-generators", + "transform-async-to-generator" + ] +} \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..6b03e4a --- /dev/null +++ b/.jshintrc @@ -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" + ] +} \ No newline at end of file diff --git a/dist/.gitkeep b/dist/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/index.js b/index.js new file mode 100644 index 0000000..ad6d3cd --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +require('babel-register'); +require('./server'); diff --git a/package.json b/package.json new file mode 100644 index 0000000..cb6de13 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/server/config.js b/server/config.js new file mode 100644 index 0000000..350c245 --- /dev/null +++ b/server/config.js @@ -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; diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..9fea109 --- /dev/null +++ b/server/index.js @@ -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;