This repository was archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
74 lines (58 loc) · 1.86 KB
/
index.ts
File metadata and controls
74 lines (58 loc) · 1.86 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import cors from 'cors';
import express from 'express';
import fs from 'fs';
import https from 'https';
const app = express();
import Day from './Functions/Day';
import Days from './Functions/Days';
import getRates from './Functions/getRates';
import getRatesEvening from './Functions/getRatesEvening';
import Month from './Functions/Month';
import Rate from './Functions/Rate';
import rateEvening from './Functions/RateEvening';
const localPath = '/home/pi/datas/';
const key = fs.readFileSync('../certs/selfsigned.key');
const cert = fs.readFileSync('../certs/selfsigned.crt');
const options = {
key: key,
cert: cert
};
const server = https.createServer(options, app);
server.listen(8080, () => {
console.log('Server started !');
});
app.use(express.json());
app.use(cors());
app.use((err: { status: number }, req: any, res: any, next: Function) => {
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
return res.sendStatus(400);
}
next();
});
app.get('/', (req: any, res: any) => {
res.status(200).json({ error: 0, msg: 'Online !' });
});
app.get('/menus', (req: any, res: any) => {
res.status(200).json({ error: 0, msg: 'To access a menu, get /menus/month/day/. To access all the month menus, get /menus/month' });
});
app.post('/menus', (req: any, res: any) => {
Days(req, res, localPath);
});
app.get('/menus/:month/:day', (req: any, res: any) => {
Day(req, res, localPath);
});
app.get('/menus/:month', (req: any, res: any) => {
Month(req, res, localPath);
});
app.post('/rates/:month/:day', (req: any, res: any) => {
Rate(req, res, localPath);
});
app.get('/rates/:month/:day', (req: any, res: any) => {
getRates(req, res, localPath);
});
app.post('/ratesEvening/:month/:day', (req: any, res: any) => {
rateEvening(req, res, localPath);
});
app.get('/ratesEvening/:month/:day', (req: any, res: any) => {
getRatesEvening(req, res, localPath);
});