Skip to content

Commit cb43636

Browse files
Added new route for home page
1 parent 00624c4 commit cb43636

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ API documentation is written inline and generated by [apidoc](http://apidocjs.co
6767
Visit `http://localhost:3000/docs/` to view docs
6868

6969
## Contributors
70-
Systango, Arpit Khandelwal
70+
Arpit Khandelwal (https://github.com/arpit-systango)
7171

7272
## License
7373
MIT

bin/server.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,40 @@ import session from 'koa-generic-session'
77
import passport from 'koa-passport'
88
import mount from 'koa-mount'
99
import serve from 'koa-static'
10-
1110
import config from '../config'
1211
import { errorMiddleware } from '../src/middleware'
1312

1413
const app = new Koa()
1514
app.keys = [config.session]
1615

16+
// --------------------- start -------------------------
17+
//Instead of calling convert for all legacy middlewares
18+
//just use the following to convert them all at once
19+
20+
const _use = app.use
21+
app.use = x => _use.call(app, convert(x))
22+
23+
//The code above avoids writting the following
24+
//app.use(convert(logger()))
25+
// ---------------------- end --------------------------
26+
1727
mongoose.Promise = global.Promise
1828
mongoose.connect(config.database)
1929

20-
app.use(convert(logger()))
30+
app.use(logger())
2131
app.use(bodyParser())
2232
app.use(session())
2333
app.use(errorMiddleware())
2434

25-
app.use(convert(mount('/docs', serve(`${process.cwd()}/docs`))))
35+
//Mount static API documents generated by api-generator
36+
app.use(mount('/docs', serve(`${process.cwd()}/docs`)))
2637

38+
//Using Passport for authentication
2739
require('../config/passport')
2840
app.use(passport.initialize())
2941
app.use(passport.session())
3042

43+
//Using module wise routing
3144
const modules = require('../src/modules')
3245
modules(app)
3346

src/modules/home/controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export async function getHome (ctx) {
2+
ctx.body = '<b>The KOACH is here!</b>'
3+
}
4+
5+
export async function getLogin (ctx) {
6+
ctx.body = '<b>The KOACH login page is WIP.</b>'
7+
}

src/modules/home/router.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as home from './controller'
2+
3+
export const baseUrl = '/'
4+
5+
export default [
6+
{
7+
method: 'GET',
8+
route: '/',
9+
handlers: [
10+
home.getHome
11+
]
12+
},
13+
{
14+
method: 'GET',
15+
route: 'login',
16+
handlers: [
17+
home.getLogin
18+
]
19+
}
20+
]

0 commit comments

Comments
 (0)