-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (32 loc) · 1.24 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
const Express = require("express");
const Cors = require("cors");
const Path = require("path");
const FileSystem = require("fs");
const Utils = require("./utils");
// Setup express
const app = Express();
const port = process.env.PORT || 3000;
// Use cors (for json requests from browser or something)
app.use(Cors());
// Set the public folder for serving static
// stuff (normal plain html website thing)
app.use(Express.static(Path.join(__dirname, "public")));
// Router endpoints (stuff from other files)
app.use("/apis/speedrun", require("./apis/speedrun/speedrun"));
// Endpoints and whatnot
app.get("/test", (request, response) => {
response.send("<h1>testing rn</h1>");
})
// Make it so that all pages don't have
// the .html part at the end of them
app.get("*", (request, response) => {
// Get the stuff we're after
const requestedContent = request.params[0];
const page = Path.join(__dirname, "public", `${requestedContent}.html`);
// Check for if the page exists. If it does then
// send them the page. Otherwise pack a sad
if (FileSystem.existsSync(page)) response.sendFile(page);
else Utils.SendCustomError(requestedContent, 404, response);
});
// Run the express server
app.listen(port, () => console.log(`Server listening on port ${port}!`));