A pastebin for markdown pages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
942 B

11 years ago
var express = require('express');
var page = require('./src/page');
var storage = require('./src/storage');
10 years ago
var LRU = require("lru-cache");
11 years ago
var app = express();
10 years ago
var CACHE = new LRU(30);
11 years ago
app.use(express.static(__dirname + '/resources/public'));
app.get('/new', function (req, res) {
res.send("opening new note mask")
});
11 years ago
app.get("/:year/:month/:day/:title", function (req, res) {
var P = req.params;
storage.getNoteId(P.year + "/" + P.month + "/" + P.day + "/" + P.title)
.then(id => res.redirect("/" + id));
});
app.get(/\/([a-zA-Z0-9]*)/, function (req, res) {
var link = req.params["0"].toLowerCase();
10 years ago
if (CACHE.has(link)) res.send(CACHE.get(link));
else storage.getNote(link).then(note => {
var content = page.build(note);
CACHE.set(link, content);
res.send(content);
});
10 years ago
});
var server = app.listen(3000, function () {
console.log('NoteHub server listening on port %s', server.address().port);
});