Add index.js and routes

This commit is contained in:
Yarmo Mackenbach 2020-08-08 01:06:58 +02:00
parent 22e1b565ae
commit 1ab13275b6
7 changed files with 231 additions and 0 deletions

24
index.js Normal file
View file

@ -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}`);
});

39
routes/encrypt.js Normal file
View file

@ -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;

32
routes/main.js Normal file
View file

@ -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;

19
routes/profile.js Normal file
View file

@ -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;

39
routes/proofs.js Normal file
View file

@ -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;

39
routes/util.js Normal file
View file

@ -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;

39
routes/verify.js Normal file
View file

@ -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;