-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
60 lines (44 loc) · 1.48 KB
/
Copy pathapp.js
File metadata and controls
60 lines (44 loc) · 1.48 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import express from 'express';
const app = express()
const port = 3000
import path from 'path';
import userAPIRoutes from './routes/user_api.js';
import dateAPIRoutes from './routes/date_api.js';
import converterAPIRoutes from './routes/converter_api.js';
import pgAPIRoutes from './routes/postgres_api.js';
import handler from './database/controller.js'
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import bodyParser from 'body-parser';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public', {
maxAge: '300000',
etag: true,
lastModified: true
}))
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/public/ocean.html'))
})
app.get('/simple', (req, res) => {
res.sendFile(path.join(__dirname, '/public/simple.html'))
})
app.get('/myapi', (req, res) => {
res.sendFile(path.join(__dirname, '/public/myapi.html'))
})
userAPIRoutes(app);
dateAPIRoutes(app);
converterAPIRoutes(app);
pgAPIRoutes(app)
app.use((req, res, next) => {
res.status(404).sendFile(path.join(__dirname, '404.html'))
})
app.use((req, res, next) => {
res.status(505).sendFile(path.join(__dirname, '505.html'))
})
app.listen(port, () => {
console.log(`Listening on port ${port}...`);
})
export default app