-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (40 loc) · 1.26 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
45
46
47
48
require('dotenv').config();
const express = require('express');
// Basic Configuration
const port = process.env.PORT || 3000;
const app = express();
const cors = require("cors");
// Set up mongoose connection
const mongoose = require("mongoose");
mongoose.set("strictQuery", false);
const mongoDB = process.env.MONGODB_URI;
main().catch((err) => console.log(err));
async function main() {
await mongoose.connect(mongoDB);
}
app.use(cors());
app.use('/public', express.static(`${process.cwd()}/public`));
app.get('/', function(req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});
const shorterRouter = require('./routes/shorter');
app.use('/api/shorturl', shorterRouter);
app.listen(port, function() {
console.log(`Listening on port ${port}`);
});
// I misunderstood I should use Array
// Array of URL
// const arrayOfUrl = [
// { number: 1, url: "e" },
// { number: 2, url: "boilerplate-project-urlshortener.memorandum876.repl.co" },
// { number: 3, url: "b" }
// ];
// // Function check whether reqesut URL is in array
// const isUrlInArray = (hostUrl, number) => {
// for (let item of arrayOfUrl) {
// if (item.number == number && item.url == hostUrl) {
// return item; // Return the matched item
// }
// }
// return null;
// };