-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (22 loc) · 785 Bytes
/
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
const express = require("express");
const app = express();
const http = require("http").Server(app);
const path = require("path");
let PORT = process.env.PORT || 4444;
//Start serveur
http.listen(PORT, () => {
console.log("Serveur lancé sur http://localhost:" + PORT);
});
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.use("/assets", express.static(__dirname + "/assets"));
app.use("/", express.static(__dirname));
app.get("/:folder/:name", (req, res) => {
// if name is not a html file, redirect to index
if (req.params.name.indexOf(".html") === -1 && req.params.name.split(".").length > 1) {
res.redirect("/");
} else {
res.sendFile(path.join(__dirname, req.params.folder + "/" + req.params.name));
}
});