-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
59 lines (42 loc) · 1.52 KB
/
server.js
File metadata and controls
59 lines (42 loc) · 1.52 KB
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
57
58
59
// import package statement
import express from "express";
import bodyParser from "body-parser";
import morgan from "morgan";
import dotenv from "dotenv"
import methodOverride from "method-override"
import { route } from "./server/routes/route.js";
import { fileURLToPath } from "url";
import path from 'path'
import cors from "cors"
// import custom files
import {notFound } from "../JokeAPI+SwaggerDocs/server/controllers/controller.js"
import swaggerDocs from "./swagger.js";
// Initialization
const server = express();
dotenv.config({path: 'info.env'})
const masterKey = process.env.MASTER_KEY;
// middleware
// server.use(methodOverride('_method'));
server.use(cors())
// server.use(methodOverride('X-HTTP-Method-Override'));
// server.use(methodOverride('_method'));
server.use(express.json())
server.use(bodyParser.urlencoded({ extended: true }));
server.use(morgan("tiny"))
// Resolve the path to the "public" directory
// const publicPath = path.join(fileURLToPath(import.meta.url), "../public")
// console.log(typeof publicPath);
// console.log(publicPath);
server.use(express.static("public"))
// Resolve the path to the 'views' directory
const viewsPath = path.resolve(fileURLToPath(import.meta.url), "../views")
server.set('views', viewsPath)
// Seting up views engine
server.set("view engine", "ejs");
const PORT = process.env.PORT || 4000
route(server)
swaggerDocs(server, PORT)
server.use(notFound)
server.listen(PORT, () => {
console.log(`Successfully started server on http://localhost:${PORT}/jokeapi/docs`);
});