aboutsummaryrefslogtreecommitdiffstats
path: root/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'server.js')
-rwxr-xr-xserver.js40
1 files changed, 19 insertions, 21 deletions
diff --git a/server.js b/server.js
index 8ebab87..a9f2973 100755
--- a/server.js
+++ b/server.js
@@ -25,29 +25,16 @@ app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.engine("ejs", require("ejs").__express);
-app.get("/$", (req, res) => {
- let readStream = fs.createReadStream(
- path.join(__dirname, "mds", "cstruct2luatable.md"),
- "utf-8"
- );
- readStream.on("data", (chunk) => {
- res.render("index", {
- cache: true,
- data: {
- blogHttp: mit.render(chunk),
- mds: fs.readdirSync(path.join(__dirname, "mds"), "utf-8"),
- },
- });
- });
-});
-
-app.get("/mds/:mdname$", (req, res) => {
- if (req.params["mdname"] == "") {
- res.write("nothing requested!");
- }
+function renderAndSend(req, res) {
try {
+ let viewPath;
+ if (req.path == "/") {
+ viewPath = "mds/cstruct2luatable.md";
+ } else {
+ viewPath = req.path;
+ }
let readStream = fs.createReadStream(
- path.join(__dirname, req.path),
+ path.join(__dirname, viewPath),
"utf-8"
);
readStream.on("data", (chunk) => {
@@ -62,6 +49,17 @@ app.get("/mds/:mdname$", (req, res) => {
} catch (err) {
console.log(err);
}
+}
+
+app.get("/$", (req, res) => {
+ renderAndSend(req, res);
+});
+
+app.get("/mds/:mdname$", (req, res) => {
+ if (req.params["mdname"] == "") {
+ res.write("nothing requested!");
+ }
+ renderAndSend(req, res);
});
app.listen(9000);