From ae511a3871e0d41e14c6a842f0b4ba445005eac1 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Tue, 25 Feb 2025 16:02:31 -0500 Subject: [PATCH] boilerplate more --- index.js | 19 +----- init.js | 38 +++++++++++ public/icon.svg | 90 ++++++++++--------------- public/logout.svg | 50 ++++++++++++++ public/walls.svg | 167 ++++++++++++++++++++++++++++++++++++++++++++++ views/header.ejs | 6 +- views/root.ejs | 4 +- views/vblock.ejs | 1 + 8 files changed, 301 insertions(+), 74 deletions(-) create mode 100644 init.js create mode 100644 public/logout.svg create mode 100644 public/walls.svg create mode 100644 views/vblock.ejs diff --git a/index.js b/index.js index 76d917a..92b9268 100644 --- a/index.js +++ b/index.js @@ -1,28 +1,15 @@ import express from "express"; +import { doInit } from "./init.js"; const app = express() const port = 3000; app.use(express.static('public')); app.set('view engine', 'ejs'); +app.enable('view cache'); app.listen(port, () => { console.log(`Example app listening on port ${port}`) }) -app.use((req, res, next) => { - res.ctx = { - mainPage: '404.ejs', - mainCtx: {}, - headerCtx: {} - }; - next(); -}) - -app.use('/api', (req, res, next) => { - res.send(res.ctx); -}) - -app.use((req, res, next) => { - res.render('root.ejs', res.ctx) -}) \ No newline at end of file +doInit(app); \ No newline at end of file diff --git a/init.js b/init.js new file mode 100644 index 0000000..43cf4ba --- /dev/null +++ b/init.js @@ -0,0 +1,38 @@ +const aliases = { + '/': '/walls/get/home' +}; + +function doAliases(app) { + for (let alias in aliases) { + app.all(alias, (req,res,next) => { + res.redirect(aliases[alias]) + }) + } +} + +function doInit(app) { + app.use((req, res, next) => { + res.ctx = { + mainPage: '404.ejs', + mainCtx: {}, + headerCtx: [ + { link: '/walls/get/home', icon: '/icon.svg', name: 'DervNet' }, + { link: '/walls/list', icon: '/walls.svg', name: 'Explore' }, + { link: '/you/logout', icon: '/logout.svg', name: 'Leave' } // fix icon + ] + }; + next(); + }) + + doAliases(app); + + app.use('/api', (req, res, next) => { + res.send(res.ctx); + }) + + app.use((req, res, next) => { + res.render('root.ejs', res.ctx) + }) +} + +export { doInit }; \ No newline at end of file diff --git a/public/icon.svg b/public/icon.svg index c4d26c9..ef8f14e 100644 --- a/public/icon.svg +++ b/public/icon.svg @@ -2,20 +2,20 @@ - - - - - - - - - - - - - - + cx="75.947723" + cy="87.13208" + r="1.38166" /> diff --git a/public/logout.svg b/public/logout.svg new file mode 100644 index 0000000..bb6c1bb --- /dev/null +++ b/public/logout.svg @@ -0,0 +1,50 @@ + + + + diff --git a/public/walls.svg b/public/walls.svg new file mode 100644 index 0000000..970207f --- /dev/null +++ b/public/walls.svg @@ -0,0 +1,167 @@ + + + + diff --git a/views/header.ejs b/views/header.ejs index 6b5fbb6..77d879e 100644 --- a/views/header.ejs +++ b/views/header.ejs @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/views/root.ejs b/views/root.ejs index 65a26b3..5ef2494 100644 --- a/views/root.ejs +++ b/views/root.ejs @@ -3,13 +3,13 @@ DervNet - + - <%- include('header.ejs',headerCtx); %> + <%- include('header.ejs',{headerCtx}); %> <%- include(mainPage, mainCtx); %> diff --git a/views/vblock.ejs b/views/vblock.ejs new file mode 100644 index 0000000..9f5547c --- /dev/null +++ b/views/vblock.ejs @@ -0,0 +1 @@ +<%= name %> \ No newline at end of file