-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (44 loc) · 1.21 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
49
50
51
52
53
54
55
56
#!/usr/bin/env node
import * as dotenv from "dotenv";
dotenv.config();
import express from "express";
import fs from "fs";
import cors from "cors";
import https from "https";
import { apiv1 } from "./routes/apiv1.js";
import { apiv2 } from "./routes/apiv2.js";
import { apiv3 } from "./routes/apiv3.js";
const app = express();
const PORT = process.env.PORT || 5000;
// Creating object of key and certificate
// for SSL
// const options = {
// key: fs.readFileSync("server.key"),
// cert: fs.readFileSync("server.cert"),
// };
//static folder for serving icons
app.use(express.static("icons"))
//middleware
app.use(cors())
app.use(express.json()) //for raw json
app.use(express.urlencoded({ extended: false }))
app.all('/*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
next();
});
function reportRequest(req, res, next) {
console.log(req.url);
next()
}
app.use(reportRequest);
//ROUTES
app.use("/api/v1", apiv1);
app.use("/api/v2", apiv2);
app.use("/api/v3", apiv3)
// https.createServer(options, app)
// .listen(PORT, function (req, res){
// console.log(`Server running on PORT: ${PORT}`)
// });
app.listen(PORT, () => {
console.log(`Server running on PORT: ${PORT}`);
})