-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
40 lines (35 loc) · 1.08 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as express from 'express'
import { Request, Response, NextFunction } from 'express'
import * as bodyParser from 'body-parser'
import routes from './app/routes'
import { PORT } from './app/configs'
const app = express()
app.use(bodyParser.json())
app.set('json spaces', 2)
app.use(bodyParser.urlencoded({ extended: true }))
app.set('trust proxy', true)
function logging(req: Request, res: Response, next: NextFunction) {
const log = {
body: req.body,
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
method: req.method,
url: req.originalUrl,
params: req.params,
query: req.query,
}
console.log(log)
next()
}
function accessControl(req: Request, res: Response, next: NextFunction) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Content-Type,Authorization,Cache-Control,Accept,Accept-Encoding')
next()
}
// Routes
app.use(logging)
app.use(accessControl)
app.use('/', routes.api)
app.use('/', routes.datasets)
// Start Listening
app.listen(PORT)
console.log(`Listening on PORT ${ PORT }`)