From 88d21fae34ba1633abf909b9a4213a60476d16cf Mon Sep 17 00:00:00 2001 From: John Datserakis Date: Sat, 15 Jul 2017 22:57:52 -0400 Subject: [PATCH] initial setup --- .gitignore | 2 ++ ecosystem.json | 17 +++++++++++++++++ index.js | 14 ++++++++++++++ package.json | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 3 +++ src/app.js | 27 +++++++++++++++++++++++++++ src/router.js | 8 ++++++++ 7 files changed, 119 insertions(+) create mode 100755 .gitignore create mode 100644 ecosystem.json create mode 100644 index.js create mode 100644 package.json create mode 100644 readme.md create mode 100755 src/app.js create mode 100755 src/router.js diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..5171c54 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log \ No newline at end of file diff --git a/ecosystem.json b/ecosystem.json new file mode 100644 index 0000000..5acf847 --- /dev/null +++ b/ecosystem.json @@ -0,0 +1,17 @@ +{ + "apps" : [ + { + "name" : "koa-vue-notes-api", + "script" : "index.js", + "merge_logs" : true, + "env": { + "NODE_ENV": "production", + "PORT": 4000 + }, + "instances": 2, + "exec_mode" : "cluster_mode", + "autorestart": true, + "log_date_format": "YYYY-MM-DD HH:mm Z" + } + ] +} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..fccd318 --- /dev/null +++ b/index.js @@ -0,0 +1,14 @@ +'use strict'; + +const env = process.env.NODE_ENV || 'development'; +const port = process.env.PORT || 4000; +const src = env === 'production' ? './build/app' : './src/app'; + +require('babel-polyfill'); +if (env === 'development') { + require('babel-register'); +} + +const app = require(src).default; +app.listen(port); +console.log('Server running at ' + port); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..20595e2 --- /dev/null +++ b/package.json @@ -0,0 +1,48 @@ +{ + "name": "koa-vue-notes-api", + "version": "0.0.1", + "description": "A SPA using Koa as the backend and Vue as the frontend.", + "author": "John Datserakis", + "private": true, + "scripts": { + "start": "node index.js", + "watch": "nodemon --exec npm run start", + "test": "npm run build; mocha --require 'babel-polyfill' --compilers js:babel-register", + "build": "babel src -d build" + }, + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/OrKoN/koa2-example-app.git" + }, + "keywords": [ + "data", + "node" + ], + "license": "MIT", + "homepage": "https://github.com/OrKoN/koa2-example-app#readme", + "dependencies": { + "babel-polyfill": "^6.5.0", + "kcors": "^2.0.0", + "koa": "^2.0.0-alpha.3", + "koa-bodyparser": "^3.0.0", + "koa-router": "^7.0.1", + "promise-redis": "0.0.5", + "redis": "^2.4.2" + }, + "devDependencies": { + "babel-cli": "^6.5.1", + "babel-preset-es2015": "^6.5.0", + "babel-preset-stage-3": "^6.5.0", + "babel-register": "^6.9.0", + "chai": "^3.5.0", + "mocha": "^2.4.5", + "nodemon": "^1.9.2", + "supertest": "^1.2.0" + }, + "babel": { + "presets": [ + "es2015", + "stage-3" + ] + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..22baca2 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +#SPA using Koa as the backend and Vue as the frontend. + +Work In Progress. \ No newline at end of file diff --git a/src/app.js b/src/app.js new file mode 100755 index 0000000..04d34fb --- /dev/null +++ b/src/app.js @@ -0,0 +1,27 @@ +import Koa from 'koa'; +import router from './router'; +import bodyParser from 'koa-bodyparser'; +import cors from 'kcors'; + +const app = new Koa() + +//For cors +app.use(cors()) + +//For managing body +app.use(bodyParser()) + +//For router +app.use(router.routes()) +app.use(router.allowedMethods()); + +//Birds-eye processing +app.use(async (ctx, next) => { + try { + await next(); + } catch (error) { + throw error; + } +}) + +export default app; \ No newline at end of file diff --git a/src/router.js b/src/router.js new file mode 100755 index 0000000..9b9d732 --- /dev/null +++ b/src/router.js @@ -0,0 +1,8 @@ +import Router from 'koa-router' +const router = new Router() + +router.get('/', async (ctx, next) => { + ctx.body = 'Hello' +}) + +export default router \ No newline at end of file