Example
commit
c38a1a5216
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
yarn-error.log
|
@ -0,0 +1,24 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const express = require("express");
|
||||||
|
const knex = require("knex");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const config = require("./config.json");
|
||||||
|
const indexRouters = require("./routers/index");
|
||||||
|
|
||||||
|
let db = knex({ /* ... config options go here ... */});
|
||||||
|
|
||||||
|
let dependencies = {
|
||||||
|
db: db,
|
||||||
|
config: config
|
||||||
|
};
|
||||||
|
|
||||||
|
let app = express();
|
||||||
|
|
||||||
|
app.set("view engine", "pug");
|
||||||
|
app.set("views", path.join(__dirname, "views"));
|
||||||
|
|
||||||
|
app.use(indexRouters(dependencies));
|
||||||
|
|
||||||
|
app.listen(3000);
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"bestNumber": 42
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "parametric-modules-example",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"repository": "git@git.cryto.net:joepie91/parametric-modules-example.git",
|
||||||
|
"author": "Sven Slootweg <admin@cryto.net>",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"bluebird": "^3.5.3",
|
||||||
|
"express": "^4.16.4",
|
||||||
|
"express-promise-router": "^3.0.3",
|
||||||
|
"knex": "^0.16.3",
|
||||||
|
"pug": "^2.0.3",
|
||||||
|
"sqlite3": "^4.0.6"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const Promise = require("bluebird");
|
||||||
|
const expressPromiseRouter = require("express-promise-router");
|
||||||
|
|
||||||
|
module.exports = function({db}) {
|
||||||
|
let router = expressPromiseRouter();
|
||||||
|
|
||||||
|
router.get("/", (req, res) => {
|
||||||
|
return Promise.try(() => {
|
||||||
|
return db("items").where({
|
||||||
|
visible: true
|
||||||
|
});
|
||||||
|
}).then((result) => {
|
||||||
|
res.render("index", {
|
||||||
|
items: result
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/item/:id", (req, res) => {
|
||||||
|
return Promise.try(() => {
|
||||||
|
return db("items").where({
|
||||||
|
id: req.params.id
|
||||||
|
}).first();
|
||||||
|
}).then((item) => {
|
||||||
|
res.render("item", {
|
||||||
|
item: item
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
h1 Items
|
||||||
|
|
||||||
|
ul
|
||||||
|
for item in items
|
||||||
|
li: a(href=`/item/${item.id}`) Item: #{item.name}
|
@ -0,0 +1,3 @@
|
|||||||
|
h1 Item: #{item.name}
|
||||||
|
|
||||||
|
p Details would go here
|
Loading…
Reference in New Issue