-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (35 loc) · 1.08 KB
/
server.js
File metadata and controls
39 lines (35 loc) · 1.08 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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const express = require('express');
const app = express();
const PORT = process.env.PORT || 8080;
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.post('/validate', async (req, res) => {
const { guess } = req.body;
if (guess.toLowerCase() === process.env.SEKRET_RESPONSE) {
res.json({
status: 'success',
message: 'Congrats! You solved the weekly riddle!',
answer: process.env.SEKRET_RESPONSE
});
} else {
res.json({
status: 'failure',
message: 'Wrong answer! Try again!',
answer: guess
});
}
});
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}\nAccess it at http://localhost:${PORT}`);
});