-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
index.js
40 lines (34 loc) · 925 Bytes
/
index.js
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 express from "express";
const app = express();
import english from './routes/english.js';
import language from './routes/language.js';
import swaggerUi from './swagger-ui.js';
import { limiter } from "./utils/index.js";
// Apply rate limiter to all routes except root
app.use((req, res, next) => {
if (req.path !== '/') {
return limiter(req, res, next);
}
next();
});
app.use('/', swaggerUi);
app.use('/word', english);
app.use('/word', language);
app.use('/api-docs', swaggerUi);
app.use('/', function(_req, res) {
res.status(404).json({
error: 1,
message: 'Page or Data not Found'
});
})
app.use((err, req, res, next) => {
if (!err) return next();
return res.status(403).json({
error: 1,
message: 'Page or Data not Found'
});
});
const port = process.env.PORT || 3002;
app.listen(port, function() {
console.log('listening on port ' + port);
});