2020-01-27 01:41:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const http = require('http');
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
const hostname = '0.0.0.0';
|
|
|
|
const port = 3000;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
2020-01-27 02:45:54 +00:00
|
|
|
var logic = require('./logic.js');
|
2020-01-27 01:41:23 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
function getPage(req) {
|
|
|
|
var route = req.url.substring(1);
|
2020-01-27 02:45:54 +00:00
|
|
|
var query = logic.riddle_me(route);
|
2020-01-27 01:41:23 +00:00
|
|
|
|
|
|
|
console.log(`Serving route ${route}`);
|
|
|
|
|
|
|
|
return `<html>
|
|
|
|
<head>
|
2020-01-27 02:45:54 +00:00
|
|
|
<title>${query.question}?</title>
|
|
|
|
<link href="https://fonts.googleapis.com/css?family=Bowlby+One+SC|Special+Elite&display=swap"
|
|
|
|
rel="stylesheet">
|
|
|
|
<style type="text/css">
|
|
|
|
.question {
|
|
|
|
font-family: 'Special Elite', cursive;
|
|
|
|
font-size: xx-large;
|
|
|
|
text-align: center;
|
|
|
|
margin-top: 200px;
|
|
|
|
}
|
|
|
|
.answer {
|
|
|
|
font-family: 'Bowlby One SC', cursive;
|
|
|
|
font-size: 200px;
|
|
|
|
text-align: center;
|
|
|
|
margin-top: 20px;
|
|
|
|
margin-bottom: 20px;
|
|
|
|
}
|
|
|
|
.yes {
|
|
|
|
color: green;
|
|
|
|
}
|
|
|
|
.no {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
</style>
|
2020-01-27 01:41:23 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2020-01-27 02:45:54 +00:00
|
|
|
<p class="question">${query.question}?</p>
|
|
|
|
<p class="answer ${query.answer}">${query.answer}!</p>
|
2020-01-27 01:41:23 +00:00
|
|
|
</body>
|
|
|
|
</html>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
const server = http.createServer((req, res) => {
|
|
|
|
res.statusCode = 200;
|
|
|
|
res.setHeader('Content-Type', 'text/html');
|
|
|
|
res.write(getPage(req));
|
|
|
|
res.end();
|
|
|
|
console.log(`Serviced request ${req}`);
|
|
|
|
}).listen(port, hostname, () => {
|
|
|
|
console.log(`Server running at http://${hostname}:${port}/`);
|
|
|
|
});
|