import * as express from 'express' ; import * as next from 'next' ; import * as bodyParser from 'body-parser' ; import * as cookieParser from 'cookie-parser' ; import * as helmet from 'helmet' ; import * as morgan from 'morgan' ; import * as mongoose from 'mongoose' ; import * as passport from 'passport' ; import config from './config' ; import authRoutes from './routes/authRoutes' ; import entryRoutes from './routes/entryRoutes' ; import reviewRoutes from './routes/reviewRoutes' ; import tagsRoutes from './routes/tagsRoutes' ; import appRoutes from './routes/appRoutes' ; import * as errorController from './controllers/errorController' ; import './bot' ; import './passport' ; import './cron' ; const app = next ( { dev : config . is_dev } ) ; const handle = app . getRequestHandler ( ) ; mongoose . connect ( config . db_uri ) ; app . prepare ( ) . then ( ( ) => { const server = express ( ) ; server . use ( helmet ( ) ) ; if ( config . is_dev ) { server . use ( morgan ( 'dev' ) ) ; } server . use ( cookieParser ( ) ) ; server . use ( bodyParser . json ( ) ) ; server . use ( bodyParser . urlencoded ( { extended : true } ) ) ; server . use ( passport . initialize ( ) ) ; server . use ( express . static ( 'static' ) ) ; server . use ( '/api/auth' , authRoutes ) ; server . use ( '/api/entry' , entryRoutes ) ; server . use ( '/api/review' , reviewRoutes ) ; server . use ( '/api/tags' , tagsRoutes ) ; server . use ( '/api' , errorController . notFound ) ; server . use ( '/' , appRoutes ( app ) ) ; server . use ( errorController . send ) ; server . get ( '/sw.js' , ( _req , res ) => { res . sendFile ( __dirname + '/offline/sw.js' ) ; } ) ; server . get ( '*' , ( req , res ) => handle ( req , res ) ) ; server . listen ( config . port , err => { if ( err ) throw err ; console . log ( `> Ready on http://localhost:${ config . port }` ) ; } ) ; } ) ;