aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server.js58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/server.js b/src/server.js
index 773feb0..58d29fb 100644
--- a/src/server.js
+++ b/src/server.js
@@ -7,6 +7,7 @@ const uuidv4 = require('uuid/v4');
const path = require('path');
const rss = require('rss');
const marked = require('marked');
+const cache = require('apicache').middleware;
const templates = require('./templates');
@@ -125,27 +126,30 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
next()
})
- server.get('/', async (req, res) => {
+ server.get('/', cache('5 minutes'), async (req, res) => {
let posts = await formatPostsForType(models, "index")
let body = templates["index"]({posts});
res.status(200).send(body)
})
- server.get('/bread', async (req, res) => {
+ server.get('/bread', cache('5 minutes'), async (req, res) => {
let posts = await formatPostsForType(models, "bread")
let body = templates["bread"]({posts});
res.status(200).send(body)
})
- server.get('/blog', async (req, res) => {
+ server.get('/blog', cache('5 minutes'), async (req, res) => {
let posts = await formatPostsForType(models, "blog")
let body = templates["blog"]({posts});
res.status(200).send(body)
})
- server.get('/post/:type/:id', async (req, res) => {
+ server.get('/post/:type/:id', cache('5 minutes'), async (req, res) => {
let posts = await formatPostsforSingle(models, req.params.type, req.params.id)
let date = posts[0].createdAt;
let body = templates["blog-single"]({posts, date});
res.status(200).send(body)
})
+<<<<<<< HEAD
+ server.get('/tags/:name', cache('5 minutes'), async (req, res) => {
+=======
server.get('/post/like/:type/:id', async (req, res) => {
let type = req.params.type
let id = req.params.id
@@ -156,6 +160,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
res.status(200).send({likes: post.likes});
})
server.get('/tags/:name', async (req, res) => {
+>>>>>>> 5b5dc610bc0da17fd006982de50b4dc74b134a54
const { name } = req.params;
const postsWithTag = await models.tags.findAll({ attributes: ["postId"], where: { text: name } })
.map(function (x) {
@@ -174,30 +179,29 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
res.status(200).send(body)
})
- server.get('/admin', (req, res) => res.sendFile(__dirname + "/html/admin.html"));
- server.get('/login', (req, res) => res.sendFile(__dirname + "/html/login.html"))
- server.get('/email', (req, res) => res.sendFile(__dirname + "/html/email.html"))
- server.get('/email-success', (req, res) => res.sendFile(__dirname + "/html/email-success.html"))
- server.get('/feed', (req, res) => res.sendFile(__dirname + "/html/feed.html"));
- server.get('/essay', (req, res) => res.sendFile(__dirname + "/html/essay.html"));
- // server.get('/misc', (req, res) => res.sendFile(__dirname + "/html/misc.html"));
- server.get('/word-square', (req, res) => res.sendFile(__dirname + "/html/word-square.html"));
- server.get('/chess', (req, res) => res.sendFile(__dirname + "/html/chess.html"));
- server.get('/admin/chess', async (req, res, next) => res.sendFile(__dirname + "/html/chess.html"));
+ server.get('/admin', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/admin.html"));
+ server.get('/login', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/login.html"))
+ server.get('/email', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/email.html"))
+ server.get('/email-success', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/email-success.html"))
+ server.get('/feed', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/feed.html"));
+ server.get('/essay', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/essay.html"));
+ server.get('/word-square', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/word-square.html"));
+ server.get('/chess', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/chess.html"));
+ server.get('/admin/chess', cache('5 minutes'), async (req, res, next) => res.sendFile(__dirname + "/html/chess.html"));
// server.get('/projects', (req, res) => res.sendFile(__dirname + "/html/projects.html"));
- server.get('/zines', (req, res) => res.sendFile(__dirname + "/public/zines.html"));
+ server.get('/zines', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/public/zines.html"));
server.use('/static', express.static(__dirname + '/public'))
- server.get('/misc', async (req, res) => {
+ server.get('/misc', cache('5 minutes'), async (req, res) => {
let body = templates["misc"]();
res.status(200).send(body)
})
- server.get('/projects', async (req, res) => {
+ server.get('/projects', cache('5 minutes'), async (req, res) => {
let body = templates["projects"]();
res.status(200).send(body)
})
- server.get('/wordsquares/best', async (req, res, next) => {
+ server.get('/wordsquares/best', cache('5 minutes'), async (req, res, next) => {
var best = await database.query("select words, name from wordsquares where best = 1", { type: database.QueryTypes.SELECT })
res.status(200).send({ best: best });
})
@@ -231,7 +235,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
res.status(400).send(e.message);
}
})
- server.get('/posts/:type', async (req, res, next) => {
+ server.get('/posts/:type', cache('5 minutes'), async (req, res, next) => {
try {
const { type } = req.params;
var posts = await models.posts.findAll({
@@ -245,7 +249,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
res.status(400).send(e.message);
}
})
- server.get('/posts/:type/:id', async (req, res, next) => {
+ server.get('/posts/:type/:id', cache('5 minutes'), async (req, res, next) => {
try {
const { type, id } = req.params;
var posts = await models.posts.findAll({
@@ -334,25 +338,25 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
})
- server.get('/favicon.ico', (req, res) => res.sendFile(__dirname + "/res/favicon.ico"))
- server.get('/favicon.svg', (req, res) => res.sendFile(__dirname + "/res/favicon.svg"))
- server.get('/css/:id', (req, res) => {
+ server.get('/favicon.ico', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/icon/favicon.ico"))
+ server.get('/favicon.svg', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/icon/favicon.svg"))
+ server.get('/css/:id', cache('5 minutes'), (req, res) => {
res.sendFile(__dirname + "/css/" + req.params.id);
});
- server.get('/uploads/:id', (req, res) => {
+ server.get('/uploads/:id', cache('5 minutes'), (req, res) => {
res.sendFile(__dirname + "/uploads/" + req.params.id);
});
- server.get('/essay/:id', (req, res) => {
+ server.get('/essay/:id', cache('5 minutes'), (req, res) => {
res.sendFile(__dirname + "/html/essay/" + req.params.id);
});
- server.get('/js/:id', (req, res) => {
+ server.get('/js/:id', cache('5 minutes'), (req, res) => {
res.sendFile(__dirname + "/js/" + req.params.id);
});
server.get('/res/:id', (req, res) => {
res.sendFile(__dirname + "/res/" + req.params.id);
});
- server.get('/feed.xml', async (req, res) => {
+ server.get('/feed.xml', cache('1 hour'), async (req, res) => {
var feed = new rss({
title: "Mark's Kitchen",
description: "Posts from marks.kitchen",