forked from franpoh/groupproject2-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (41 loc) · 1.6 KB
/
index.js
File metadata and controls
52 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { sequelize, testConnection, Users, Index, Swap, Reviews, Genres } = require("./connect.js");
const { protectedPermission, adminPermission } = require("./authentication/userPermissions");
const express = require('express');
const app = express();
const generalRoutes = require("./routes/generalRoutes.js");
const protectedRoutes = require("./routes/protectedRoutes.js");
// Test connections
testConnection();
// Parsing JSON
app.use(express.json());
// Adding middleware to all protected routes
const authenticateJwt = require("./authentication/authJwt");
app.use('/protected', authenticateJwt, protectedPermission);
app.use('/protected/admin', adminPermission);
// Main Page
app.get('/', async (req, res) => {
res.send("Welcome to the bookswap!");
});
// Testing database connections
app.get('/test', async (req, res) => {
const users = await Users.findAll();
const index = await Index.findAll();
const swap = await Swap.findAll();
const reviews = await Reviews.findAll();
const genres = await Genres.findAll();
// res.send(JSON.stringify([users, index, swap, reviews, genres]));
res.json([index, users, swap, genres, reviews]); //AuntPyone testing
});
// auntpyone dev: delete reviews
app.delete("/testDel/:reviewId", async (req, res) => {
const index = Reviews.findByPk(req.params.reviewId);
await (await index).destroy();
res.status(200);
return res.send("Delete successful");
})
// Sign in routes (Register, Login) AND public user requests
app.use(generalRoutes);
// registered users options - requests
app.use(protectedRoutes);
// Port listening
app.listen(process.env.PORT);