-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc3d8f9
commit 6ddbc8e
Showing
15 changed files
with
155 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,81 @@ | ||
import { install as installSourceMapSupport } from 'source-map-support'; | ||
installSourceMapSupport(); | ||
// import { install as installSourceMapSupport } from 'source-map-support'; | ||
// installSourceMapSupport(); | ||
import 'reflect-metadata'; | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
import * as express from 'express'; | ||
import * as compress from 'compression'; | ||
import * as cors from 'cors'; | ||
import app from './server'; | ||
import errorHandler from './common/errors/error.handler'; | ||
import errorHandler from './core/error.handler'; | ||
import logger from './core/logger'; | ||
import initDB from './core/database'; | ||
import database from './core/database'; | ||
import container from './core/inversify'; | ||
import ApplicationRouter from './router'; | ||
|
||
/** | ||
* This is a bootstrap function | ||
*/ | ||
async function bootstrap() { | ||
// Attach HTTP request info logger middleware in test mode | ||
if (process.env.NODE_ENV === 'test') { | ||
app.use((req: express.Request, _res, next) => { | ||
logger.debug(`[${req.method}] ${req.hostname}${req.url}`); | ||
const app = express(); | ||
|
||
next(); | ||
}); | ||
} | ||
app.disable('x-powered-by'); | ||
app.use(compress()); | ||
|
||
app.disable('x-powered-by'); | ||
app.use(compress()); | ||
// Enable middleware/whatever only in Production | ||
if (process.env.NODE_ENV === 'production') { | ||
// For example: Enable sentry in production | ||
// app.use(Sentry.Handlers.requestHandler()); | ||
} | ||
|
||
// Enable middleware/whatever only in Production | ||
if (process.env.NODE_ENV === 'production') { | ||
// For example: Enable sentry in production | ||
// app.use(Sentry.Handlers.requestHandler()); | ||
} | ||
/** | ||
* Configure cors | ||
*/ | ||
app.use(cors()); | ||
|
||
/** | ||
* Configure cors | ||
*/ | ||
app.use(cors()); | ||
/** | ||
* Configure database | ||
**/ | ||
if (!database.isConnected()) { | ||
database | ||
.connect() | ||
.then(() => { | ||
database.emit('connected'); | ||
logger.info('Database connected'); | ||
}) | ||
.catch((err) => { | ||
logger.error('Database connection error', err); | ||
}); | ||
} | ||
|
||
/** | ||
* Configure database | ||
**/ | ||
if (!initDB.isDbConnected()) { | ||
await initDB.connect(); | ||
} | ||
/** | ||
* Configure body parser | ||
*/ | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
|
||
/** | ||
* Configure body parser | ||
*/ | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
/** | ||
* Host static public directory | ||
*/ | ||
app.use('/', express.static('public')); | ||
|
||
/** | ||
* Host static public directory | ||
*/ | ||
app.use('/', express.static('public')); | ||
/** | ||
* Configure routes | ||
*/ | ||
// Let inversify resolve the dependency | ||
const router = container.get<ApplicationRouter>(ApplicationRouter); | ||
router.register(app); | ||
|
||
/** | ||
* Configure routes | ||
*/ | ||
// Let inversify resolve the dependency | ||
const router = container.get<ApplicationRouter>(ApplicationRouter); | ||
router.register(app); | ||
/** | ||
* Configure error handler | ||
*/ | ||
errorHandler(app); | ||
|
||
/** | ||
* Configure error handler | ||
*/ | ||
errorHandler(app); | ||
} | ||
/** | ||
* Setup listener port | ||
*/ | ||
const PORT = process.env.PORT || 3000; | ||
app.listen(PORT, () => { | ||
logger.info(`Running Node.js version ${process.version}`); | ||
logger.info(`App environment: ${process.env.NODE_ENV}`); | ||
logger.info(`App is running on port ${PORT}`); | ||
}); | ||
|
||
// Need for integration testing | ||
export default app; | ||
|
||
// Invoking the bootstrap function | ||
bootstrap() | ||
.then(() => { | ||
logger.info('Server is up'); | ||
}) | ||
.catch((error) => { | ||
logger.error('Unknown error. ' + error.message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.