-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (30 loc) · 969 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
36
37
38
import express from "express";
import dotenv from "dotenv";
import { connectDB } from "./config/db.connection.js";
import { errorHandler } from "./middlewares/error-handler.js";
import { limiter } from "./middlewares/rate-limit.js";
import {
createShortUrl,
goToShortUrl,
showHomePage,
deleteUrl
} from "./controllers/url.js";
const app = express();
dotenv.config();
app.use(express.urlencoded({ extended: false }));
app.set("view engine", "ejs");
app.use(express.static("public"));
await connectDB();
app.use(limiter);
app.get("/", showHomePage);
app.post("/short-url", createShortUrl);
app.get("/:shortUrl", goToShortUrl); // add this at the end of all other routes with get
app.delete("/deleteUrl/:urlId", deleteUrl);
app.all("*", (req, res) => {
return res.status(404).send({ message: "Route not found" });
});
app.use(errorHandler);
const PORT = process.env.PORT;
app.listen(PORT, () => {
console.log(`listening on port ${PORT}`);
});