-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 934 Bytes
/
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
import express from "express";
import dotenv from "dotenv";
import cookieParser from "cookie-parser";
import cors from "cors";
import database from "./src/config/database.js";
import { root, register } from "./src/routes/users.js";
import { feed } from "./src/routes/feed.js";
// loads environment variables
dotenv.config();
const app = express();
const corsOptions = { credentials: true, origin: "http://localhost:3000" };
// database authentication
try {
await database.authenticate();
console.log("Database Connected...");
} catch (error) {
console.log(error);
}
// parsers: cookies, json, request_body
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// allow CORS
app.use(cors(corsOptions));
// route_handlers
app.use("/", root);
app.use("/hook", register);
app.use("/api/feed", feed);
app.listen(5001, () => console.log("hookedu: Server Running on Port 5001..."));