From a10cc7fcb8c4093e21e61596815bfa21804e0c64 Mon Sep 17 00:00:00 2001 From: Vincent Phung Date: Mon, 19 Jun 2023 21:17:32 -0700 Subject: [PATCH] Refactor server routes for better handling of static files --- .DS_Store | Bin 6148 -> 6148 bytes build/index.html | 29 ++++++++++- build/reset.css | 124 ----------------------------------------------- server.js | 12 ++++- 4 files changed, 38 insertions(+), 127 deletions(-) delete mode 100644 build/reset.css diff --git a/.DS_Store b/.DS_Store index d13d19eee5250bd27c7ae07a4c7176bf961d23d1..9fa0fa91d52a3db2b99fd78ff75c848763e976b8 100644 GIT binary patch delta 104 zcmZoMXfc=|#>B)qu~2NHo}w@_0|Nsi1A_nqLrPh2QC?1dUi#*bj4K(XK@zMCNerb7 snG87yNs#i*Jd6)nH?wo_a{$c&s{YPAnP0?`1858oF)(Zn5ZS^E0QvtH#sB~S delta 84 zcmZoMXfc=|#>B`mu~2NHo}wrd0|Nsi1A_oVaY0f}eiD$kJ*i+~;qu7_A}pIVneMS} jY>;By%+A5j0o1cukoi0FWPTA#4xl=aHm1!1B3qaNSQryS diff --git a/build/index.html b/build/index.html index 8d57710..acd5860 100644 --- a/build/index.html +++ b/build/index.html @@ -1 +1,28 @@ -ravenous
\ No newline at end of file + + + + + + + + + + + ravenous + + + + + +
+ + diff --git a/build/reset.css b/build/reset.css deleted file mode 100644 index afb3bf4..0000000 --- a/build/reset.css +++ /dev/null @@ -1,124 +0,0 @@ -html, -body, -div, -span, -applet, -object, -iframe, -h1, -h2, -h3, -h4, -h5, -h6, -p, -blockquote, -pre, -a, -abbr, -acronym, -address, -big, -cite, -code, -del, -dfn, -em, -img, -ins, -kbd, -q, -s, -samp, -small, -strike, -strong, -sub, -sup, -tt, -var, -b, -u, -i, -center, -dl, -dt, -dd, -ol, -ul, -li, -fieldset, -form, -label, -legend, -table, -caption, -tbody, -tfoot, -thead, -tr, -th, -td, -article, -aside, -canvas, -details, -embed, -figure, -figcaption, -footer, -header, -hgroup, -menu, -nav, -output, -ruby, -section, -summary, -time, -mark, -audio, -video { - margin: 0; - padding: 0; - border: 0; - font-size: 100%; - font: inherit; - vertical-align: baseline; -} -/* HTML5 display-role reset for older browsers */ -article, -aside, -details, -figcaption, -figure, -footer, -header, -hgroup, -menu, -nav, -section { - display: block; -} -body { - line-height: 1; -} -ol, -ul { - list-style: none; -} -blockquote, -q { - quotes: none; -} -blockquote:before, -blockquote:after, -q:before, -q:after { - content: ""; - content: none; -} -table { - border-collapse: collapse; - border-spacing: 0; -} diff --git a/server.js b/server.js index 3e63829..55c3d8e 100644 --- a/server.js +++ b/server.js @@ -8,8 +8,15 @@ app.use(cors()); const apiKey = process.env.API_KEY; +// Serve static files from the React app app.use(express.static(path.join(__dirname, 'build'))); +// Handle the requests for the individual files like main.js, main.css, etc. +app.get(/^\/(static|favicon\.ico|manifest\.json|logo192\.png)/, (req, res) => { + const filePath = path.join(__dirname, 'build', req.url); + res.sendFile(filePath); +}); + app.get('/search', (req, res) => { axios({ method: 'get', @@ -26,8 +33,9 @@ app.get('/search', (req, res) => { }); }); -app.get('/*', (req, res) => { - res.sendFile(path.join(__dirname, 'build', 'index.html')); +// The "catchall" handler: for any request that doesn't match one above, send back React's index.html file. +app.get('*', (req, res) => { + res.sendFile(path.join(__dirname, 'build', 'index.html')); }); const port = process.env.PORT || 3000;