aboutsummaryrefslogtreecommitdiffstats
path: root/server.js
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2021-04-11 08:10:09 +0000
committerterminaldweller <thabogre@gmail.com>2021-04-11 08:10:09 +0000
commit64347c601fcb30904857e3ffc3b4d54a617b6441 (patch)
tree42e338c15dde925174e4313c623bdb2edaa67941 /server.js
parentadded a dockerfile. fixed the relative path issues (diff)
downloadblog-64347c601fcb30904857e3ffc3b4d54a617b6441.tar.gz
blog-64347c601fcb30904857e3ffc3b4d54a617b6441.zip
everything seems to be working now
Diffstat (limited to 'server.js')
-rwxr-xr-xserver.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/server.js b/server.js
index 82b4b07..86681e9 100755
--- a/server.js
+++ b/server.js
@@ -20,18 +20,16 @@ const mit = require("markdown-it")({ html: true })
});
const app = express();
-app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, "css")));
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.engine("ejs", require("ejs").__express);
-app.get("/", (req, res) => {
+app.get("/$", (req, res) => {
let readStream = fs.createReadStream(
- path.join(__dirname, "mds/cstruct2luatable.md"),
+ path.join(__dirname, "mds", "cstruct2luatable.md"),
"utf-8"
);
- // FIXME-this is gonna be so wrong when the md is bigger than one chunk
readStream.on("data", (chunk) => {
res.render("index", {
data: {
@@ -42,4 +40,26 @@ app.get("/", (req, res) => {
});
});
-app.listen(3000);
+app.get("/mds/:mdname$", (req, res) => {
+ if (req.params["mdname"] == "") {
+ res.write("nothing requested!");
+ }
+ try {
+ let readStream = fs.createReadStream(
+ path.join(__dirname, req.path),
+ "utf-8"
+ );
+ readStream.on("data", (chunk) => {
+ res.render("index", {
+ data: {
+ blogHttp: mit.render(chunk),
+ mds: fs.readdirSync(path.join(__dirname, "mds"), "utf-8"),
+ },
+ });
+ });
+ } catch (err) {
+ console.log(err);
+ }
+});
+
+app.listen(9000);