-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (33 loc) · 1.24 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
const express = require('express');
const path = require('path');
const predict = require('./index');
const timeToSeconds = require('./js/timeToSeconds')
const data = require('./js/data');
//sets global variables for the data times for morning and evening in seconds
global.initialMorningTimeSeconds =timeToSeconds(data.initialMorningTime);
global.endMorningTimeSeconds = timeToSeconds(data.endMorningTime);
global.initialEveningTimeSeconds = timeToSeconds(data.initialEveningTime);
global.endEveningTimeSeconds = timeToSeconds(data.endEveningTime);
const app = express();
//starts a server that listens on port 7000
const server = app.listen(7000, () => {
console.log(`Express running → PORT ${server.address().port}`);
});
//it shows the index.html file as the main page
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname+'/index.html'));
});
//used for post requests
app.use(express.urlencoded({
extended: true
}));
//recieves post requests and runs the predict function
app.post('/',(req,res)=>{
if(req.body.licensePlate=="" || req.body.date=="" || req.body.time==""){
res.send('form not filled correctly');
}
else{
let response = predict(req.body.licensePlate,req.body.date,req.body.time);
res.send(response);
}
});