forked from ZacharyRizer/paws-and-claws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (56 loc) · 1.75 KB
/
index.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require("express");
const morgan = require("morgan");
const path = require("path");
const cors = require("cors");
const fetch = require("node-fetch");
const asyncHandler = (handler) => (req, res, next) => handler(req, res, next).catch(next)
const { api, port } = require("./config");
// Create the Express app.
const app = express();
// Set up middleware
app.use(morgan('dev'));
app.use(express.static(path.join(__dirname, "public")));
// Set the pug view engine.
app.set("view engine", "pug");
//middleware for custom render
app.use((req, res, next) => {
res.locals.api = api;
next();
})
//routes
app.get('/', (req, res) => {
res.render('homepage');
});
app.get('/register', async (req, res) => {
let response = await fetch(`${api}states`);
const { states } = await response.json()
res.render('register', { states });
});
app.get('/login', (req, res) => {
res.render('login')
});
// //Only Adopter can fill out the preferred pet
app.get('/create-preferred-pet', async (req, res) => {
let response = await fetch(`${api}breeds`);
const { breeds } = await response.json();
res.render('create-pref-pet', { breeds })
});
app.get('/edit-pet/:id', async (req, res) => {
let response = await fetch(`${api}breeds`);
const { breeds } = await response.json();
res.render('edit-pet', { breeds })
})
app.get("/user-profile", async (req, res) => {
res.render('user-profile');
});
app.get("/shelter-profile", async (req, res) => {
res.render('shelter-profile');
});
app.get("/pets/:id", async (req, res) => {
res.render('pet-information')
})
app.get("/logout", function (req, res) {
res.render('logout');
});
//start listening for connections.
app.listen(port, () => console.log(`Listening on port ${port}...`));