From 1833a4ad443e15863afc979eb9a63473102d0f79 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 19 Jan 2020 12:14:05 -0600 Subject: add namespace redirect (ex: http://bogbook.com/ev) --- server.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/server.js b/server.js index 9a53943..a4f563f 100644 --- a/server.js +++ b/server.js @@ -86,6 +86,31 @@ var open = require('open') var app = new koa() +// namespace redirect -- add namespaces to ~/.bogbook/names.json +app.use(async function (ctx, next) { + if (ctx.request.url[1] != '#') { + var name = ctx.request.url.substring(1) + + if (!fs.existsSync(path + 'names.json')) { + var obj = { + ev: '@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=', + mil3s: '@531mT2x1FnQdpYJxVrG8YD9wiE767xO88kKRhi5A3Yg=', + g: '@WVBPY53Bl4aUIngt2TXV8nW+IGKvCTqhv88EvktOX9s=' + } + fs.writeFileSync(path + 'names.json', JSON.stringify(obj), 'UTF-8') + } + + var obj = JSON.parse(fs.readFileSync(path + 'names.json', 'UTF-8')) + + for (var property in obj) { + if ((name === property) || (name === property + '/')) { + ctx.redirect('/#' + obj[property]) + } + } + } + return await next() +}) + app.use(serve({rootDir: '.', notFoundFile: 'index.html'})) app.listen(config.port) -- cgit v1.2.3-70-g09d2