Skip to content

Commit 0c0c299

Browse files
authored
Refactor app.js for improved structure and CORS support
1 parent e5308c6 commit 0c0c299

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

app.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const express = require('express');
55
const path = require('path');
6-
const fs = require('fs');
6+
const fs = require('fs');
77
const cors = require('cors');
88

99
const app = express();
@@ -51,13 +51,15 @@ if (!fs.existsSync(filePath)) {
5151
// Serve static files
5252
// Serve static files from the directory containing the HTML file
5353
const fileDir = path.dirname(filePath);
54-
app.use(express.static(fileDir));
55-
app.use(
56-
cors({
57-
origin: "*",
58-
allowedHeaders: ["Content-Type", "Authorization"],
59-
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
60-
})
54+
app.use(express.static(fileDir));
55+
56+
// added cors so that anyone in netwokr can access thr html file
57+
app.use(
58+
cors({
59+
origin: "*",
60+
allowedHeaders: ["Content-Type", "Authorization"],
61+
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
62+
})
6163
);
6264

6365
// Route to handle requests
@@ -103,3 +105,4 @@ function startServer(port) {
103105

104106
// Start from port 3000
105107
startServer(3000);
108+

0 commit comments

Comments
 (0)