-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (62 loc) · 1.67 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const express = require("express");
const app = express();
const server = require("http").createServer(app);
const path = require("path");
const fs = require("fs");
const fetch = require("node-fetch");
const apiRouter = require("./routes/api");
app.set("view engine", "ejs");
app.set("views", "views");
app.set("json spaces", 2);
app.use("/js", express.static(path.join(__dirname, "js")), (_, res) => {
res.render("error", {
status: 404,
message: "Script Not Found."
});
});
app.use("/css", express.static(path.join(__dirname, "css")), (_, res) => {
res.render("error", {
status: 404,
message: "Stylesheet Not Found."
});
});
app.use("/images", express.static(path.join(__dirname, "images")), (_, res) => {
res.render("error", {
status: 404,
message: "Image Not Found."
});
});
app.get("/", (_, res) => {
fs.readFile("./README.md", "utf8", (err, file) => {
if (err) {
return res.json({status: err.number, message: err.message});
}
let data = {
"text": file,
"mode": "gfm",
"context": "FFGFlash/ffg-sudoku"
}
fetch("https://api.github.com/markdown", {
method: "POST",
body: JSON.stringify(data),
headers: {"Content-Type": "application/json"}
}).then(res=>res.text()).then(data => {
res.render("index", {
readme: data
});
}).catch(err => {
res.json({data: JSON.stringify(data), status: err.number, message: err.message});
});
});
});
app.get("/play", (_, res) => {
res.render("game");
});
app.use("/api", apiRouter);
app.use((_, res) => {
res.render("error", {
status: 404,
message: "Page Not Found."
});
});
server.listen(process.env.PORT || 80);