-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 1.09 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
const express = require("express");
const connectDB = require("./config/db");
const shortid = require("shortid");
const validUrl = require("valid-url");
const shortUrlRoute = require("./routes/shorturl")
const getShortenUrlRoute = require("./routes/getshortenurl")
const getAllUrls = require("./routes/getAllUrls")
const deleteUrl = require("./routes/deleteUrl")
const app = express();
connectDB();
app.use(express.json({}));
const PORT = 8000;
app.listen(PORT, () => console.log("Server is listening on port " + PORT));
app.use(function (req, res, next) {
// Website we wish to allow to connect, should be changed for production
res.setHeader('Access-Control-Allow-Origin', '*')
// Request methods we wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, DELETE')
// Request headers we wish to allow
res.setHeader('Access-Control-Allow-Headers', 'Authorization,X-Requested-With,content-type,XMLHttpRequest')
next()
})
app.use("/v1/", getShortenUrlRoute);
app.use("/v1/shorturl", shortUrlRoute);
app.use("/all", getAllUrls);
app.use("/delete", deleteUrl)