-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
32 lines (28 loc) · 959 Bytes
/
api.js
File metadata and controls
32 lines (28 loc) · 959 Bytes
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
import express from 'express';
import awsServerlessExpress from 'aws-serverless-express';
import { SERVICE_NAME } from './configs/constants';
import customerController from './controllers/customer-controller';
import LogService from './services/log-service';
import TraceService from './services/trace-service';
const app = express();
const server = awsServerlessExpress.createServer(app);
app
.use(express.json())
.use(TraceService.middleware())
.use(LogService.middleware())
.use((req, res, next) => {
req.log.debug('Processing request', {
host: req.get('host'),
path: req.path,
query: req.query,
headers: req.headers,
body: req.body,
});
next();
})
.use([`/${SERVICE_NAME}`, '/'], customerController)
.use((err, req, res, next) => {
req.log.error('Request processing error', err);
next(err);
});
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);