-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
77 lines (62 loc) · 2.06 KB
/
server.js
File metadata and controls
77 lines (62 loc) · 2.06 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//external imports
require("dotenv").config();
//const browserSync = require("browser-sync").create();
const express = require("express");
const cors = require("cors");
const path = require("path");
//const fs = require("fs").promises;
//NC - saving weapon data - Define the function to get the character's file path before use
const getCharacterFilePath = (userId) => {
return path.join(__dirname, "back-end", "characterdata", `${userId}.json`);
};
//variables - INITIALISE THE SECTION
const app = express();
const PORT = process.env.PORT || 3000;
const router = require("./back-end/routes/routes");
//const {
// saveCharacter,
//} = require("./back-end/controllers/controllers-characters");
//const saveCharacter = require("./back-end/controllers/controllers-characters");
//NC - Middleware and routes section
//app.use("/api", saveCharacter);
app.use(cors({
origin: "*",
methods: "GET,POST,PUT,DELETE",
allowedHeaders: ["Content-Type", "Authorization"],
credentials: true
}));
//NC - use express to parse JSON data
app.use(express.json());
// Serve static files from the "public" directory
app.use(express.static("front-end/public"));
// Define a route for the home page
app.get("/", (req, res) => {
res.sendFile(__dirname + "/front-end/public/index/index.html");
});
// Route for create.html
app.get("/create.html", (req, res) => {
res.sendFile(__dirname + "/front-end/public/create/create.html");
});
//JM test route
app.get("/lounge-tale.html", (req, res) => {
res.sendFile(__dirname + "/front-end/public/lounge/lounge-tale.html");
});
//deathpage route
app.get("/death.html", (req, res) => {
res.sendFile(__dirname + "/front-end/public/death/death.html");
});
// Route for character and weapon data
app.use(router);
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
//NC- installed to help with showing all logs
const morgan = require("morgan");
app.use(morgan("dev"));
//Browser sync setup
// browserSync.init({
// proxy: `http://localhost:${PORT}`,
// files: ["front-end/public/*/.*"],
// reloadDelay: 50,
// });