From 8250e4f98f515d1a923da3238bbb69a1c551327b Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Sat, 8 Feb 2025 18:18:15 +0100 Subject: [PATCH] send files with requests instead of serving the whole repertory in static --- src/app.js | 3 ++- src/controllers/main.js | 11 ++++++++--- src/public/index.html | 2 +- src/routes/root.js | 8 ++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app.js b/src/app.js index 5f4ddba..74ff019 100644 --- a/src/app.js +++ b/src/app.js @@ -7,8 +7,9 @@ var io = require('socket.io')(http); const cookieParser = require('cookie-parser'); app.use(cookieParser()); +// bootstrap app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css')); -app.use(express.static('public')); +// app.use(express.static('public')); const routes = require(__dirname + '/routes'); app.use("/", routes); diff --git a/src/controllers/main.js b/src/controllers/main.js index 8360cdc..e225050 100644 --- a/src/controllers/main.js +++ b/src/controllers/main.js @@ -1,9 +1,14 @@ +const path = require('path'); const mainController = { root: (req, res) => { - res.json({ - message: "Hello, World!", - }); + res.sendFile(path.resolve(__dirname + '/../public/index.html')); + }, + style: (req, res) => { + res.sendFile(path.resolve(__dirname + '/../public/style.css')); + }, + script: (req, res) => { + res.sendFile(path.resolve(__dirname + '/../public/script.js')); } }; diff --git a/src/public/index.html b/src/public/index.html index 7cfa939..8e0a5ea 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -4,7 +4,7 @@ - + diff --git a/src/routes/root.js b/src/routes/root.js index 86189bf..3e2cbb7 100644 --- a/src/routes/root.js +++ b/src/routes/root.js @@ -6,4 +6,12 @@ router .route("/") .get(mainController.root); +router + .route("/style.css") + .get(mainController.style); + +router + .route("/script.js") + .get(mainController.script); + module.exports = router;