first route
This commit is contained in:
@@ -4,10 +4,17 @@ var app = express();
|
|||||||
|
|
||||||
app.use(express.static(__dirname + '/resources/public'));
|
app.use(express.static(__dirname + '/resources/public'));
|
||||||
|
|
||||||
app.get('/api', function (req, res) {
|
app.get('/:year/:month/:day/:title', function (req, res) {
|
||||||
res.send(page.build("api"));
|
var params = req.params;
|
||||||
|
var id = params.year + "/" + params.month + "/" + params.day + "/" + params.title;
|
||||||
|
res.send("opening note " + id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/:link', function (req, res) {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
var server = app.listen(3000, function () {
|
var server = app.listen(3000, function () {
|
||||||
console.log('NoteHub server listening on port %s', server.address().port);
|
console.log('NoteHub server listening on port %s', server.address().port);
|
||||||
});
|
});
|
||||||
+1
-2
@@ -7,11 +7,10 @@ var template = fs.readFileSync("resources/template.html", "utf-8");
|
|||||||
var buildHTML = (title, content) => template
|
var buildHTML = (title, content) => template
|
||||||
.replace("%TITLE%", title)
|
.replace("%TITLE%", title)
|
||||||
.replace("%CONTENT%", content);
|
.replace("%CONTENT%", content);
|
||||||
var apiPage = buildHTML("API", marked(fs.readFileSync("API.md", "utf-8")));
|
|
||||||
|
|
||||||
module.exports.build = id => {
|
module.exports.build = id => {
|
||||||
if (CACHE.has(id)) return CACHE.get(id);
|
if (CACHE.has(id)) return CACHE.get(id);
|
||||||
var content = id == "api" ? apiPage : "This is page " + id;
|
var content = "This is page " + id;
|
||||||
CACHE.set(id, content);
|
CACHE.set(id, content);
|
||||||
return content;
|
return content;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user