-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
31 lines (26 loc) · 902 Bytes
/
app.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
require('dotenv').config();
const cors = require('cors');
const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express();
app.use(cors());
app.use(express.json());
app.set('json spaces', 2);
fs.readdirSync(path.resolve(__dirname, 'routes')).forEach(file => {
if (file.endsWith('.js')) {
const handler_file = require(path.join(__dirname, 'routes', file));
app.use(`/api${handler_file.base_route}`, cors(), handler_file.handler());
}
});
app.use('/assets', express.static('assets'));
app.use(express.static('public'));
app.use('*', (req, res) => {
res.json({
at: new Date().toISOString(), method: req.method, hostname: req.hostname, query: req.query, params: req.params
});
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server Started at http://localhost:${PORT}`);
});