Initial commit

This commit is contained in:
Flummi
2018-02-16 14:25:46 +01:00
commit d0ae0041e8
21 changed files with 732 additions and 0 deletions

30
src/fpaste.mjs Normal file
View File

@ -0,0 +1,30 @@
import cfg from "../cfg/config";
import express from "express";
import exphbs from "express-handlebars";
import router from "./routes";
const hbs = exphbs.create({
defaultLayout: "main",
helpers: {
times: (n, block) => {
let rows = [];
for(var i = 0; i < n; ++i)
rows.push(block.fn(i+1));
return rows.join("<br />");
}
}
});
const app = express();
app
.engine("handlebars", hbs.engine)
.set("view engine", "handlebars")
.use(express.static("public", cfg.websrv.static_options))
.use("/", router.index)
.use("/v", router.view)
.use("/a", router.about)
.listen(cfg.websrv.port, () => {
console.log(`fpaste listening on port ${cfg.websrv.port}`);
});

10
src/routes/index.mjs Normal file
View File

@ -0,0 +1,10 @@
import index from "./r/index";
import view from "./r/view";
import about from "./r/about";
export default {
index: index,
view: view,
about: about
};

8
src/routes/r/about.mjs Normal file
View File

@ -0,0 +1,8 @@
import express from "express";
const router = express.Router();
router.get("/", (req, res) => {
res.render("about");
});
export default router;

8
src/routes/r/index.mjs Normal file
View File

@ -0,0 +1,8 @@
import express from "express";
const router = express.Router();
router.get("/", (req, res) => {
res.render("index");
});
export default router;

33
src/routes/r/view.mjs Normal file
View File

@ -0,0 +1,33 @@
import express from "express";
const router = express.Router();
import highlight from "highlight.js";
console.log(highlight.highlightAuto("<?php\necho 'blah';\n?>"));
router.get("/", (req, res) => {
const data = {
pastes: [
{
title: "title 01",
paste: highlight.highlightAuto("<?php\necho 'blah';\n?>").value,
language: "PHP",
rows: "<?php\necho 'blah';\n?>".split(/\n/).length
},
{
title: "title 02",
paste: highlight.highlightAuto("blub").value,
language: "Plaintext",
rows: "blub".split(/\n/).length
},
{
title: "title 03",
paste: highlight.highlightAuto("muh").value,
language: "Plaintext",
rows: "muh".split(/\n/).length
}
]
};
res.render("view", data);
});
export default router;