-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (37 loc) · 1.05 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
const express = require(`express`);
require(`dotenv`).config();
const cors = require(`cors`);
const app = express();
const dbConnection = require("./knex/knex");
const cookieParser = require("cookie-parser");
// Routes
const path = require("path");
const petRoutes = require("./routes/petsRoutes");
const usersRoutes = require("./routes/usersRoutes");
const PORT = process.env.PORT || 8080;
app.use(express.json());
app.use(cookieParser());
app.use("/images", express.static("images"));
app.use(
cors({
origin: ["http://localhost:3000", "https://petadoption-client.vercel.app"],
credentials: true,
})
);
app.use("/pets", petRoutes);
app.use("/users", usersRoutes);
app.use("*", (req, res) => {
res.status(404).send({ messege: "Oops page not found" });
});
app.use((err, req, res) => {
console.log(err);
res.status(500).send("Something broke!");
});
dbConnection.migrate.latest().then((migration) => {
if (migration) {
console.log(`connected to db`, migration);
app.listen(PORT, () => {
console.log(`Listening on ${PORT}`);
});
}
});