starter code for br
const cookieParser = require('cookie-parser');
const express = require('express');
const app = express();
app.use(cookieParser());
app.use(express.json());
let tokens = {};
/* Pages */
app.get('/', (req, res) => {
res.send(parseHTML(`
Hello, world!
`, "page", req.cookies))
});
/* API */
// ...
/* 404 */
app.get('/*', (req, res) => {
res.send(parseHTML(`
404
`, "404", req.cookies))
});
/* Functions */
function parseHTML(content, title, cookies) {
if (cookies.token || tokens[cookies.token]) {
let userid = tokens[cookies.token];
return `<!DOCTYPE html>
<html>
<head>
<title>${title}</title>
</head>
<body>
<!-- navigation here -->
${content}
</body>
</html>`;
}
}
app.listen(8000);