-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathapp.js
More file actions
65 lines (48 loc) · 1.33 KB
/
app.js
File metadata and controls
65 lines (48 loc) · 1.33 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
const express = require('express');
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
app.use(express.static(path.join(__dirname, "public")));
const { randomQuestion, getDifficulty } = require('./functions');
app.use(bodyParser.urlencoded({extended: true}));
app.listen(process.env.PORT || 3000, ()=>{
console.log("Server Started.");
});
app.get("/", (req, res)=>{
res.sendFile(__dirname+"/index.html");
});
app.get("/random", (req, res) =>{
res.json(randomQuestion());
});
app.get("/difficulty/1", (req, res)=>{
res.json(getDifficulty(1));
});
app.get("/difficulty/2", (req, res)=>{
res.json(getDifficulty(2));
});
app.get("/difficulty/3", (req, res)=>{
res.json(getDifficulty(3));
});
app.get("/difficulty/4", (req, res)=>{
res.json(getDifficulty(4));
});
app.get("/difficulty/5", (req, res)=>{
res.json(getDifficulty(5));
});
//app.use(app.router);
app.use(function(req, res, next){
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.sendFile(__dirname + "/404.html");
return;
}
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
//process.env.PORT || 5000