aboutsummaryrefslogtreecommitdiff
path: root/src/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.js')
-rw-r--r--src/server.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/server.js b/src/server.js
index 5bbb980..1f0573c 100644
--- a/src/server.js
+++ b/src/server.js
@@ -66,6 +66,8 @@ function setUpRoutes(models, jwtFunctions, database) {
server.get('/admin', (req, res) => res.sendFile(__dirname + "/html/admin.html"));
server.get('/login', (req, res) => res.sendFile(__dirname + "/html/login.html"))
server.get('/bread', (req, res) => res.sendFile(__dirname + "/html/bread.html"));
+ server.get('/blog', (req, res) => res.sendFile(__dirname + "/html/blog.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('/snake', (req, res) => res.sendFile(__dirname + "/html/snake.html"));
server.get('/setScore', (req, res) => {
@@ -82,6 +84,9 @@ function setUpRoutes(models, jwtFunctions, database) {
res.status(400).send(e.message);
}
})
+ server.get('/blog/:id', async (req, res, next) => {
+
+ });
server.get('/posts/:type', async (req, res, next) => {
try {
const { type } = req.params;
@@ -90,6 +95,9 @@ function setUpRoutes(models, jwtFunctions, database) {
for (const post of posts) {
const images = await models.pictures.findAll({ attributes: ["source"], where: { postId: post.id } }).map(x => x.source);
post.images = images;
+ const tags = await models.tags.findAll({ attributes: ["text"], where: { postId: post.id } }).map(x => x.text);
+ console.log(tags);
+ post.tags= tags;
}
res.status(200).send(posts);
next();
@@ -105,6 +113,9 @@ function setUpRoutes(models, jwtFunctions, database) {
await models.pictures.create({ "source": "uploads/" + file.filename, "postId": newPost.id });
console.log("uploaded ", file.path);
})
+ req.body.tags.split(" ").forEach(async (tag) => {
+ await models.tags.create({ "text": tag, "postId": newPost.id});
+ })
console.log(newPost);
res.redirect(`/${type}`);
next();
@@ -137,6 +148,9 @@ function setUpRoutes(models, jwtFunctions, database) {
server.get('/essay/:id', (req, res) => {
res.sendFile(__dirname + "/html/essay/" + req.params.id);
});
+ server.get('/js/:id', (req, res) => {
+ res.sendFile(__dirname + "/js/" + req.params.id);
+ });
}