|
1 | 1 | /** |
2 | | - * APPLICATION CONFIGURATION |
| 2 | + * EXPRESS TYPESCRIPT BOILERPLATE |
3 | 3 | * ---------------------------------------- |
4 | 4 | * |
5 | | - * This is the place to add any other express module and register |
6 | | - * all your custom middlewares and routes. |
| 5 | + * Gery Hirscheld<@hirsch88> |
| 6 | + * |
| 7 | + * This is a boilerplate for Node.js Application written in TypeScript. |
| 8 | + * The basic layer of this app is express. For further information visit |
| 9 | + * the 'README.md' file. |
| 10 | + * |
| 11 | + * It is very important the '/core' module is loaded first, because this |
| 12 | + * module loads all essentials third-party-libs and our configs we need. |
| 13 | + * |
| 14 | + * To add express modules go to the 'app.ts' file. All the IOC registrations |
| 15 | + * are in the 'container.ts' file. |
7 | 16 | */ |
8 | 17 |
|
9 | | -import * as path from 'path'; |
10 | | -import * as cors from 'cors'; |
11 | | -import * as morgan from 'morgan'; |
12 | | -import * as helmet from 'helmet'; |
13 | | -import * as express from 'express'; |
14 | | -import * as favicon from 'serve-favicon'; |
15 | | -import * as bodyParser from 'body-parser'; |
16 | | -import * as compression from 'compression'; |
17 | | -import { bootstrap } from './core/Bootstrap'; |
18 | | -import { Log } from './core/log'; |
19 | | - |
20 | | - |
21 | | -bootstrap.configureExpress((app: express.Application) => app |
22 | | - |
23 | | - // Enabling the cors headers |
24 | | - .options('*', cors()) |
25 | | - .use(cors()) |
26 | | - |
27 | | - // Helmet helps you secure your Express apps by setting various HTTP headers. It's not a silver bullet, but it can help! |
28 | | - .use(helmet()) |
29 | | - .use(helmet.noCache()) |
30 | | - .use(helmet.hsts({ |
31 | | - maxAge: 31536000, |
32 | | - includeSubdomains: true |
33 | | - })) |
| 18 | +// Helps to add metadata to classes with annotations |
| 19 | +import 'reflect-metadata'; |
34 | 20 |
|
35 | | - // Compress response bodies for all request that traverse through the middleware |
36 | | - .use(compression()) |
| 21 | +// Defines the main dependencies and returns the |
| 22 | +// bootstrap instance to get the server started. |
| 23 | +import { App } from './core/App'; |
| 24 | +import { CustomConfig } from './config/CustomConfig'; |
37 | 25 |
|
38 | | - // Parse incoming request bodies in a middleware before your handlers, available under the req.body property. |
39 | | - .use(bodyParser.json()) |
40 | | - .use(bodyParser.urlencoded({ |
41 | | - extended: true |
42 | | - })) |
| 26 | +export const app = new App([ |
43 | 27 |
|
44 | | - // Serve static filles like images from the public folder |
45 | | - .use(express.static(path.join(__dirname, 'public'), { maxAge: 31557600000 })) |
| 28 | + // Here you can add more custom configurations |
| 29 | + new CustomConfig() |
46 | 30 |
|
47 | | - // A favicon is a visual cue that client software, like browsers, use to identify a site |
48 | | - .use(favicon(path.join(__dirname, 'public', 'favicon.ico'))) |
| 31 | +]); |
49 | 32 |
|
50 | | - // HTTP request logger middleware for node.js |
51 | | - .use(morgan('dev', { |
52 | | - stream: { |
53 | | - write: Log.info |
54 | | - } |
55 | | - })) |
56 | | -); |
| 33 | +// Launch the server with all his awesome features. |
| 34 | +app.main(); |
0 commit comments