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회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠