bodyparser

This commit is contained in:
Flummi 2018-02-19 10:33:11 +01:00
parent 7405165c98
commit 22211749dd
2 changed files with 8 additions and 4 deletions

View File

@ -9,6 +9,7 @@
"author": "Flummi", "author": "Flummi",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.2", "express": "^4.16.2",
"express-handlebars": "^3.0.0", "express-handlebars": "^3.0.0",
"highlight.js": "^9.12.0", "highlight.js": "^9.12.0",

View File

@ -1,6 +1,7 @@
import cfg from "../cfg/config"; import cfg from "../cfg/config";
import express from "express"; import express from "express";
import exphbs from "express-handlebars"; import exphbs from "express-handlebars";
import bodyParser from "body-parser";
import router from "./routes"; import router from "./routes";
const hbs = exphbs.create({ const hbs = exphbs.create({
@ -11,6 +12,9 @@ const hbs = exphbs.create({
for(var i = 0; i < n; ++i) for(var i = 0; i < n; ++i)
rows.push(block.fn(i+1)); rows.push(block.fn(i+1));
return rows.join("<br />"); return rows.join("<br />");
},
stringify: (obj) => {
return JSON.stringify(obj);
} }
} }
}); });
@ -20,15 +24,14 @@ app
.engine("handlebars", hbs.engine) .engine("handlebars", hbs.engine)
.set("view engine", "handlebars") .set("view engine", "handlebars")
.use(express.static("public", cfg.websrv.static_options)) .use(express.static("public", cfg.websrv.static_options))
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
.use("/", router.index) .use("/", router.index)
.use("/v", router.view) .use("/v", router.view)
.use("/a", router.about) .use("/a", router.about)
.use("/test", router.newpaste)
.get("/:uuid", (req, res) => { .get("/:uuid", (req, res) => res.redirect(`/v/${req.params.uuid}/`))
res.send(req.params.uuid);
})
.listen(cfg.websrv.port, () => { .listen(cfg.websrv.port, () => {
console.log(`fpaste listening on port ${cfg.websrv.port}`); console.log(`fpaste listening on port ${cfg.websrv.port}`);