Skip to content

Commit 9c93b62

Browse files
Initial commit to Koach
0 parents  commit 9c93b62

27 files changed

Lines changed: 1155 additions & 0 deletions

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"es2015-node5",
4+
"stage-0"
5+
]
6+
}

.editorconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# http://editorconfig.org
2+
3+
# A special property that should be specified at the top of the file outside of
4+
# any sections. Set to true to stop .editor config file search on current file
5+
root = true
6+
7+
[*]
8+
# Indentation style
9+
# Possible values - tab, space
10+
indent_style = space
11+
12+
# Indentation size in single-spaced characters
13+
# Possible values - an integer, tab
14+
indent_size = 2
15+
16+
# Line ending file format
17+
# Possible values - lf, crlf, cr
18+
end_of_line = lf
19+
20+
# File character encoding
21+
# Possible values - latin1, utf-8, utf-16be, utf-16le
22+
charset = utf-8
23+
24+
# Denotes whether to trim whitespace at the end of lines
25+
# Possible values - true, false
26+
trim_trailing_whitespace = true
27+
28+
# Denotes whether file should end with a newline
29+
# Possible values - true, false
30+
insert_final_newline = true

.eslintrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": "standard",
4+
"env": {
5+
"node": true,
6+
"mocha": true
7+
}
8+
}

.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Created by https://www.gitignore.io/api/node,sublimetext
2+
3+
### Node ###
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21+
.grunt
22+
23+
# node-waf configuration
24+
.lock-wscript
25+
26+
# Compiled binary addons (http://nodejs.org/api/addons.html)
27+
build/Release
28+
29+
# Dependency directory
30+
node_modules
31+
32+
# Optional npm cache directory
33+
.npm
34+
35+
# Optional REPL history
36+
.node_repl_history
37+
38+
39+
### SublimeText ###
40+
# cache files for sublime text
41+
*.tmlanguage.cache
42+
*.tmPreferences.cache
43+
*.stTheme.cache
44+
45+
# workspace files are user-specific
46+
*.sublime-workspace
47+
48+
# project files should be checked into the repository, unless a significant
49+
# proportion of contributors will probably not be using SublimeText
50+
*.sublime-project
51+
52+
# sftp configuration file
53+
sftp-config.json
54+
55+
#Documentation
56+
docs

LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2017 Arpit Khandelwal <arpit@systango.com>
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#KOACH
2+
3+
Production ready boilerplate for building APIs with [koa2] and mongodb.
4+
5+
This project covers basic necessities of most APIs.
6+
* Authentication (passport & jwt)
7+
* Database (mongoose)
8+
* Testing (mocha)
9+
* Doc generation with apidoc
10+
* linting using standard
11+
12+
##Requirements
13+
* node > v7.8.0
14+
15+
##Installation
16+
```bash
17+
git clone
18+
```
19+
20+
##Features
21+
* [koa2](https://github.com/koajs/koa)
22+
* [koa-router](https://github.com/alexmingoia/koa-router)
23+
* [koa-bodyparser](https://github.com/koajs/bodyparser)
24+
* [koa-generic-session](https://github.com/koajs/generic-session)
25+
* [koa-logger](https://github.com/koajs/logger)
26+
* [MongoDB](http://mongodb.org/)
27+
* [Mongoose](http://mongoosejs.com/)
28+
* [Passport](http://passportjs.org/)
29+
* [Nodemon](http://nodemon.io/)
30+
* [Mocha](https://mochajs.org/)
31+
* [apidoc](http://apidocjs.com/)
32+
* [Babel](https://github.com/babel/babel)
33+
* [ESLint](http://eslint.org/)
34+
35+
##Structure
36+
```
37+
├── bin
38+
│ └── server.js # Bootstrapping and entry point
39+
├── config # Server configuration settings
40+
│ ├── env # Environment specific config
41+
│ │ ├── common.js
42+
│ │ ├── development.js
43+
│ │ ├── production.js
44+
│ │ └── test.js
45+
│ ├── index.js # Config entrypoint - exports config according to envionrment and commons
46+
│ └── passport.js # Passportjs config of strategies
47+
├── src # Source code
48+
│ ├── modules
49+
│ │ ├── controller.js # Module-specific controllers
50+
│ │ └── router.js # Router definitions for module
51+
│ ├── models # Mongoose models
52+
│ └── middleware # Custom middleware
53+
│ └── validators # Validation middleware
54+
└── test # Unit tests
55+
```
56+
57+
##Usage
58+
* `npm start` Start server on live mode
59+
* `npm run dev` Start server on dev mode with nodemon
60+
* `npm run docs` Generate API documentation
61+
* `npm test` Run mocha tests
62+
63+
##Documentation
64+
API documentation is written inline and generated by [apidoc](http://apidocjs.com/).
65+
66+
Visit `http://localhost:3000/docs/` to view docs
67+
68+
##Contributors
69+
Systango, Arpit Khandelwal
70+
71+
##License
72+
MIT

bin/server.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Koa from 'koa'
2+
import bodyParser from 'koa-bodyparser'
3+
import convert from 'koa-convert'
4+
import logger from 'koa-logger'
5+
import mongoose from 'mongoose'
6+
import session from 'koa-generic-session'
7+
import passport from 'koa-passport'
8+
import mount from 'koa-mount'
9+
import serve from 'koa-static'
10+
11+
import config from '../config'
12+
import { errorMiddleware } from '../src/middleware'
13+
14+
const app = new Koa()
15+
app.keys = [config.session]
16+
17+
mongoose.Promise = global.Promise
18+
mongoose.connect(config.database)
19+
20+
app.use(convert(logger()))
21+
app.use(bodyParser())
22+
app.use(session())
23+
app.use(errorMiddleware())
24+
25+
app.use(convert(mount('/docs', serve(`${process.cwd()}/docs`))))
26+
27+
require('../config/passport')
28+
app.use(passport.initialize())
29+
app.use(passport.session())
30+
31+
const modules = require('../src/modules')
32+
modules(app)
33+
34+
app.listen(config.port, () => {
35+
console.log(`Server started on ${config.port}`)
36+
})
37+
38+
export default app

config/env/common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
port: process.env.PORT || 3000
3+
}

config/env/development.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
session: 'secret-boilerplate-token',
3+
token: 'secret-jwt-token',
4+
database: 'mongodb://localhost:27017/koach-dev'
5+
}

config/env/production.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
session: 'secret-boilerplate-token',
3+
token: 'secret-jwt-token',
4+
database: 'mongodb://localhost:27017/koach-prod'
5+
}

0 commit comments

Comments
 (0)