From 299b8c140430983016ca9435cbe6b8b67efe9198 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Mon, 11 Nov 2024 13:47:18 +0300 Subject: [PATCH] refactor: serve static files from a dedicated directory --- package-lock.json | 4 ++-- index.html => public/index.html | 0 script.js => public/script.js | 0 styles.css => public/styles.css | 0 server.js | 5 ++--- 5 files changed, 4 insertions(+), 5 deletions(-) rename index.html => public/index.html (100%) rename script.js => public/script.js (100%) rename styles.css => public/styles.css (100%) diff --git a/package-lock.json b/package-lock.json index d077334..8b89394 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "calendar-merger", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "calendar-merger", - "version": "1.0.0", + "version": "1.1.0", "license": "ISC", "dependencies": { "axios": "^1.7.7", diff --git a/index.html b/public/index.html similarity index 100% rename from index.html rename to public/index.html diff --git a/script.js b/public/script.js similarity index 100% rename from script.js rename to public/script.js diff --git a/styles.css b/public/styles.css similarity index 100% rename from styles.css rename to public/styles.css diff --git a/server.js b/server.js index 1ee1831..3a6ea0c 100644 --- a/server.js +++ b/server.js @@ -13,9 +13,8 @@ console.log(`Merged calendars directory: ${MERGED_CALENDARS_DIR} under ${process // Ensure the merged calendars directory exists fs.mkdirSync(MERGED_CALENDARS_DIR, { recursive: true }); -// Serve static files -app.get('/script.js', (req, res) => res.sendFile('script.js', { root: '.' })); -app.get('/', (req, res) => res.sendFile('index.html', { root: '.' })); +// Serve static files from the 'public' directory +app.use(express.static(path.join(process.cwd(), 'public'))); // Utility to sanitize filenames const sanitizeFilename = (filename) => filename.replace(/[<>:"/\\|?* ]/g, '_');