From 1ab13275b66e7f41aa5db26ebafd0f4f15b49878 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Sat, 8 Aug 2020 01:06:58 +0200 Subject: [PATCH] Add index.js and routes --- index.js | 24 ++++++++++++++++++++++++ routes/encrypt.js | 39 +++++++++++++++++++++++++++++++++++++++ routes/main.js | 32 ++++++++++++++++++++++++++++++++ routes/profile.js | 19 +++++++++++++++++++ routes/proofs.js | 39 +++++++++++++++++++++++++++++++++++++++ routes/util.js | 39 +++++++++++++++++++++++++++++++++++++++ routes/verify.js | 39 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 231 insertions(+) create mode 100644 index.js create mode 100644 routes/encrypt.js create mode 100644 routes/main.js create mode 100644 routes/profile.js create mode 100644 routes/proofs.js create mode 100644 routes/util.js create mode 100644 routes/verify.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..90e930e --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +const express = require('express'); +const md = require('markdown-it')({typographer: true}); +const fs = require('fs'); +const app = express(); +const port = 3000; +const env = {}; + +md.use(require("markdown-it-anchor")); +md.use(require("markdown-it-table-of-contents"), { "includeLevel": [2, 3], "listType": "ol" }); +md.use(require('markdown-it-title')); + +app.set('view engine', 'pug'); +app.use('/static', express.static('static')); +app.use('/favicon.svg', express.static('favicon.svg')); + +app.use('/', require('./routes/main')); +app.use('/encrypt', require('./routes/encrypt')); +app.use('/verify', require('./routes/verify')); +app.use('/proofs', require('./routes/proofs')); +app.use('/', require('./routes/profile')); + +app.listen(port, () => { + console.log(`Example app listening at http://localhost:${port}`); +}); diff --git a/routes/encrypt.js b/routes/encrypt.js new file mode 100644 index 0000000..e69ee10 --- /dev/null +++ b/routes/encrypt.js @@ -0,0 +1,39 @@ +var router = require('express').Router(); + +router.get('/', function(req, res) { + res.render('encrypt', { mode: "auto" }) +}); + +router.get('/wkd', function(req, res) { + res.render('encrypt', { mode: "wkd" }) +}); +router.get('/wkd/:input', function(req, res) { + res.render('encrypt', { mode: "wkd", input: req.params.input }) +}); + +router.get('/hkp', function(req, res) { + res.render('encrypt', { mode: "hkp" }) +}); +router.get('/hkp/:input', function(req, res) { + res.render('encrypt', { mode: "hkp", input: req.params.input }) +}); + +router.get('/plaintext', function(req, res) { + res.render('encrypt', { mode: "plaintext" }) +}); + +router.get('/keybase', function(req, res) { + res.render('encrypt', { mode: "keybase" }) +}); +router.get('/keybase/:username', function(req, res) { + res.render('encrypt', { mode: "keybase", username: req.params.username }) +}); +router.get('/keybase/:username/:fingerprint', function(req, res) { + res.render('encrypt', { mode: "keybase", username: req.params.username, fingerprint: req.params.fingerprint }) +}); + +router.get('/:input', function(req, res) { + res.render('encrypt', { mode: "auto", input: req.params.input }) +}); + +module.exports = router; diff --git a/routes/main.js b/routes/main.js new file mode 100644 index 0000000..8c9ff06 --- /dev/null +++ b/routes/main.js @@ -0,0 +1,32 @@ +const router = require('express').Router(); +const md = require('markdown-it')({typographer: true}); +const fs = require('fs'); +const env = {}; + +md.use(require("markdown-it-anchor")); +md.use(require("markdown-it-table-of-contents"), { "includeLevel": [2, 3], "listType": "ol" }); +md.use(require('markdown-it-title')); + +router.get('/', (req, res) => { + res.render('index') +}); + +router.get('/faq', (req, res) => { + res.render('faq'); +}); + +router.get('/guides', (req, res) => { + res.render('guides'); +}); + +router.get('/guides/:guideId', (req, res) => { + let data = fs.readFileSync(`./guides/${req.params.guideId}.md`, "utf8", (err, data) => { + if (err) throw err; + return data; + }); + + let content = md.render(data, env); + res.render(`guide`, { title: `${env.title} - Keyoxide`, content: content }) +}); + +module.exports = router; diff --git a/routes/profile.js b/routes/profile.js new file mode 100644 index 0000000..537f5c8 --- /dev/null +++ b/routes/profile.js @@ -0,0 +1,19 @@ +var router = require('express').Router(); + +router.get('/wkd/:input', function(req, res) { + res.render('profile', { mode: "wkd", uid: req.params.input }) +}); + +router.get('/hkp/:input', function(req, res) { + res.render('profile', { mode: "hkp", uid: req.params.input }) +}); + +router.get('/keybase/:username/:fingerprint', function(req, res) { + res.render('profile', { mode: "keybase", uid: `${req.params.username}/${req.params.fingerprint}` }) +}); + +router.get('/:input', function(req, res) { + res.render('profile', { mode: "auto", uid: req.params.input }) +}); + +module.exports = router; diff --git a/routes/proofs.js b/routes/proofs.js new file mode 100644 index 0000000..1d06861 --- /dev/null +++ b/routes/proofs.js @@ -0,0 +1,39 @@ +var router = require('express').Router(); + +router.get('/', function(req, res) { + res.render('proofs', { mode: "auto" }) +}); + +router.get('/wkd', function(req, res) { + res.render('proofs', { mode: "wkd" }) +}); +router.get('/wkd/:input', function(req, res) { + res.render('proofs', { mode: "wkd", input: req.params.input }) +}); + +router.get('/hkp', function(req, res) { + res.render('proofs', { mode: "hkp" }) +}); +router.get('/hkp/:input', function(req, res) { + res.render('proofs', { mode: "hkp", input: req.params.input }) +}); + +router.get('/plaintext', function(req, res) { + res.render('proofs', { mode: "plaintext" }) +}); + +router.get('/keybase', function(req, res) { + res.render('proofs', { mode: "keybase" }) +}); +router.get('/keybase/:username', function(req, res) { + res.render('proofs', { mode: "keybase", username: req.params.username }) +}); +router.get('/keybase/:username/:fingerprint', function(req, res) { + res.render('proofs', { mode: "keybase", username: req.params.username, fingerprint: req.params.fingerprint }) +}); + +router.get('/:input', function(req, res) { + res.render('proofs', { mode: "auto", input: req.params.input }) +}); + +module.exports = router; diff --git a/routes/util.js b/routes/util.js new file mode 100644 index 0000000..e69ee10 --- /dev/null +++ b/routes/util.js @@ -0,0 +1,39 @@ +var router = require('express').Router(); + +router.get('/', function(req, res) { + res.render('encrypt', { mode: "auto" }) +}); + +router.get('/wkd', function(req, res) { + res.render('encrypt', { mode: "wkd" }) +}); +router.get('/wkd/:input', function(req, res) { + res.render('encrypt', { mode: "wkd", input: req.params.input }) +}); + +router.get('/hkp', function(req, res) { + res.render('encrypt', { mode: "hkp" }) +}); +router.get('/hkp/:input', function(req, res) { + res.render('encrypt', { mode: "hkp", input: req.params.input }) +}); + +router.get('/plaintext', function(req, res) { + res.render('encrypt', { mode: "plaintext" }) +}); + +router.get('/keybase', function(req, res) { + res.render('encrypt', { mode: "keybase" }) +}); +router.get('/keybase/:username', function(req, res) { + res.render('encrypt', { mode: "keybase", username: req.params.username }) +}); +router.get('/keybase/:username/:fingerprint', function(req, res) { + res.render('encrypt', { mode: "keybase", username: req.params.username, fingerprint: req.params.fingerprint }) +}); + +router.get('/:input', function(req, res) { + res.render('encrypt', { mode: "auto", input: req.params.input }) +}); + +module.exports = router; diff --git a/routes/verify.js b/routes/verify.js new file mode 100644 index 0000000..d2437c4 --- /dev/null +++ b/routes/verify.js @@ -0,0 +1,39 @@ +var router = require('express').Router(); + +router.get('/', function(req, res) { + res.render('verify', { mode: "auto" }) +}); + +router.get('/wkd', function(req, res) { + res.render('verify', { mode: "wkd" }) +}); +router.get('/wkd/:input', function(req, res) { + res.render('verify', { mode: "wkd", input: req.params.input }) +}); + +router.get('/hkp', function(req, res) { + res.render('verify', { mode: "hkp" }) +}); +router.get('/hkp/:input', function(req, res) { + res.render('verify', { mode: "hkp", input: req.params.input }) +}); + +router.get('/plaintext', function(req, res) { + res.render('verify', { mode: "plaintext" }) +}); + +router.get('/keybase', function(req, res) { + res.render('verify', { mode: "keybase" }) +}); +router.get('/keybase/:username', function(req, res) { + res.render('verify', { mode: "keybase", username: req.params.username }) +}); +router.get('/keybase/:username/:fingerprint', function(req, res) { + res.render('verify', { mode: "keybase", username: req.params.username, fingerprint: req.params.fingerprint }) +}); + +router.get('/:input', function(req, res) { + res.render('verify', { mode: "auto", input: req.params.input }) +}); + +module.exports = router;