-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_express.js
51 lines (41 loc) · 1.25 KB
/
server_express.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
43
44
45
46
47
48
49
50
51
const { readFileSync } = require("fs");
const http = require("http");
const url = require("url");
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser());
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '0.0.0.0', // set your own ip
user : 'root',
password : 'P@ssw0rd', // no longer used
database : 'nazo_answer'
});
connection.connect();
app.post('/31337', function(req, res) {
if ( req.body.Go != undefined) {
var data = readFileSync("./answer.html");
res.end(data);
} else {
var data = readFileSync("./level8.html");
res.end(data);
}
});
app.get('*', function(req, res) {
var route = req.params[0];
connection.query('SELECT `PATH` FROM `ANSWER` WHERE `ROUTE` = "' + route + '"', function (error, results, fields) {
if (error) throw error;
if (results.length > 0) {
var data = readFileSync("./" + results[0].PATH);
res.end(data);
} else {
res.writeHead(404, {'Content-Type': 'text/html'})
var data = readFileSync("./err.html");
res.end(data);
}
});
});
app.listen("1234",()=>{
console.log("serv running on http://127.0.0.1:1234");
});