Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
johndatserakis committed Jul 16, 2017
0 parents commit 88d21fa
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
17 changes: 17 additions & 0 deletions ecosystem.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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://[email protected]/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"
]
}
}
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#SPA using Koa as the backend and Vue as the frontend.

Work In Progress.
27 changes: 27 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Router from 'koa-router'
const router = new Router()

router.get('/', async (ctx, next) => {
ctx.body = 'Hello'
})

export default router

0 comments on commit 88d21fa

Please sign in to comment.