-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (34 loc) · 1.02 KB
/
index.js
File metadata and controls
40 lines (34 loc) · 1.02 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
const express = require("express");
const cors = require("cors");
require("dotenv").config();
const app = express();
const { sequelize } = require("./db");
const port = process.env.PORT || 3000;
const userRoutes = require("./controllers/user.controller");
const franchiseRoutes = require("./controllers/franchise.controller");
const agreementRoutes = require("./controllers/agreement.controller");
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
const isProduction = process.env.NODE_ENV === "production";
sequelize
.sync({ alter: !isProduction })
.then(() => {
console.log(
isProduction
? "Database synced without altering."
: "Drop and re-sync db."
);
})
.catch((err) => {
console.log(err);
});
app.use("/users", userRoutes);
app.use("/franchises", franchiseRoutes);
app.use("/agreements", agreementRoutes);
app.get("*", (_req, res) => {
res.status(404).send("Not found");
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});