-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (32 loc) · 1.24 KB
/
server.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
const express = require('express');
const app = express();
const ejs = require('ejs');
const PORT = process.env.PORT || 3000 ;
const fs = require('fs');
const filename = __dirname + '/Settings.json';
const file = require(filename);
app.use('/', express.static('public'))
app.use(express.urlencoded({
extended: false
}))
app.set('view engine', 'ejs');
app.get('/garage' , (req, res)=>res.render('Garage'))
app.get('/', (req, res) => res.render('Start'));
app.get('/entry', (req, res) => res.render('entry', file))
app.get('/settings', (req, res) => res.render('setting'))
app.get('/about', (req, res) => res.render('About'))
app.get('/game-over', (req,res) => res.render('gameover'))
app.post('/controls', (req, res) => {
file['name'] = req.body.name;
file.controls['accelerate'] = req.body.accelerate;
file.controls['left'] = req.body.left;
file.controls['right'] = req.body.right;
file.controls['brake'] = req.body.brake;
fs.writeFile(filename, JSON.stringify(file), err => {
if (err) return console.log(err);
console.log(JSON.stringify(file));
console.log('writing to' + filename);
res.render('Start')
})
})
app.listen(PORT, () => console.log(`server running at http://localhost:${PORT}`))