-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
45 lines (36 loc) · 1.03 KB
/
handler.js
File metadata and controls
45 lines (36 loc) · 1.03 KB
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
41
42
43
44
45
const serverless = require('serverless-http');
const express = require('express');
const rateLimit = require('express-rate-limit');
const cors = require('cors');
const app = express();
require('dotenv').config();
const rateLimitConfig = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 10, // limit each IP to 100 requests per windowMs
});
const { Routes } = require('./src/routes');
const { originMiddleware } = require('./src/middlewares/origin');
app.use(express.json());
app.use(cors());
app.use(rateLimitConfig);
app.get('/', (req, res, next) => {
return res.status(200).json({
message: 'Hello from root!',
});
});
app.get('/hello', (req, res, next) => {
return res.status(200).json({
message: 'Hello from path!',
});
});
app.use('/api/services', originMiddleware, Routes);
app.use((req, res, next) => {
return res.status(404).json({
error: 'Not Found',
});
});
// Testing Purposes
// app.listen(5440, () => {
// console.log('App Running on 5440');
// });
module.exports.handler = serverless(app);