@@ -17,20 +17,20 @@ const app = new Koa()
1717app . keys = [ config . session ]
1818
1919// replace these with your certificate information
20- const options = {
21- cert : fs . readFileSync ( './cert/localhost.cert' ) ,
20+ const options = {
21+ cert : fs . readFileSync ( './cert/localhost.cert' ) ,
2222 key : fs . readFileSync ( './cert/localhost.key' )
2323}
2424
2525// --------------------- start -------------------------
26- //Instead of calling convert for all legacy middlewares
27- //just use the following to convert them all at once
26+ // Instead of calling convert for all legacy middlewares
27+ // just use the following to convert them all at once
2828
2929const _use = app . use
3030app . use = x => _use . call ( app , convert ( x ) )
3131
32- //The code above avoids writting the following
33- //app.use(convert(logger()))
32+ // The code above avoids writting the following
33+ // app.use(convert(logger()))
3434// ---------------------- end --------------------------
3535
3636mongoose . Promise = global . Promise
@@ -42,27 +42,32 @@ app.use(bodyParser())
4242app . use ( session ( ) )
4343app . use ( errorMiddleware ( ) )
4444
45- //Mount static API documents generated by api-generator
45+ // Mount static API documents generated by api-generator
4646app . use ( mount ( '/docs' , serve ( `${ process . cwd ( ) } /docs` ) ) )
4747
48- //Using Passport for authentication
48+ // Using Passport for authentication
4949require ( '../config/passport' )
5050app . use ( passport . initialize ( ) )
5151app . use ( passport . session ( ) )
5252
53- //Using module wise routing
53+ // Using module wise routing
5454const modules = require ( '../src/modules' )
5555modules ( app )
5656
57- //Using http2 to work with http/2 instead of http/1.x
58- http2
57+ // Show swagger only if the NODE_ENV is development
58+ if ( ! process . env . NODE_ENV || process . env . NODE_ENV === 'devlopment' ) {
59+ app . use ( mount ( '/swagger' , serve ( `${ process . cwd ( ) } /swagger` ) ) )
60+ }
61+
62+ // Using http2 to work with http/2 instead of http/1.x
63+ http2
5964 . createServer ( options , app . callback ( ) )
6065 . listen ( config . port , ( ) => {
6166 console . log ( `Server started on ${ config . port } ` )
62- } )
67+ } )
6368
64- //app.listen(config.port, () => {
65- //console.log(`Server started on ${config.port}`)
66- //})
69+ // app.listen(config.port, () => {
70+ // console.log(`Server started on ${config.port}`)
71+ // })
6772
6873export default app
0 commit comments