-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (32 loc) · 961 Bytes
/
index.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')
var cors = require('cors')
const app = express()
var bodyParser = require("body-parser");
var testVal = 0
app.use(cors())
app.get('/', (req, res) => res.send('Hello World!'))
app.get('/numbergame/getnumber', (req, res) => {
res.send(testVal.toString());
});
app.post('/numbergame/setnumber',function(req, res){
const userName = req.query.user;
const userNumber = req.query.number;
const expectedNumber = testVal;
console.log(req.query)
if (userNumber == expectedNumber) {
res.status(200);
res.end("CORRECT! You have claimed number: " + userNumber);
increaseVal();
return
} else {
res.end("INCORRECT! The expected number is: " + expectedNumber);
return
};
});
app.listen(process.env.PORT || 5000, () => console.log('Number app listening'))
function increaseVal() {
var tempVal = testVal
testVal += 1;
console.log('Number increased to: ' + testVal );
return tempVal;
};