Express on EC2 Only Allows Base URL

0

I have a React app with a Node/Express backend running on an EC2 instance that only works if I access the base URL. If I add anything to the URL for specific routes/pages, the app doesn't load. For instance if my site is www.example.com:

Once I load my app with the base URL, I can then navigate through my app freely with the URL updating properly but if I refresh the app anywhere the URL is not the base, it fails to load.

I can run my app locally and see the desired behavior of loading the app at any page with the corresponding URL. Looking at my logs for the backend, it appears that with any valid URL, the backend processes the request properly but on the browser, nothing is displayed except the following error in the console:

Pointer.js:29 Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".

    at new Function (<anonymous>)
    at new e (Pointer.js:29)
    at Object.<anonymous> (fontkit.browser.es.js:481)
    at Object.<anonymous> (2.cea3e404.chunk.js:2)
    at a (bootstrap:79)
    at Object.<anonymous> (pdfkit.browser.es.js:1)
    at Object.<anonymous> (2.cea3e404.chunk.js:2)
    at a (bootstrap:79)
    at Object.<anonymous> (2.cea3e404.chunk.js:2)
    at Object.<anonymous> (2.cea3e404.chunk.js:2)

Here is a snippet of my backend code that should handle all requests for the frontend app:

import express, { Request, Response } from 'express';
import path from 'path';

const router = express.Router();
export const INDEX_PATH = '/public/index.html';

router.route('/*').get((req: Request, res: Response): void => {
  res.sendFile(path.join(__dirname, INDEX_PATH));
});

export default router;

As for my AWS setup, I am running this app in an EC2 instance that is behind a load balancer. I have my domain registered with Route 53 and everything is setup to route all HTTP/HTTPS traffic to that EC2 instance via the load balancer. Please let me know if there is any further information I can provide to help figure this out! Thank you!

radqc
已提問 2 年前檢視次數 385 次
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南