reactjs - AWS Amplify redirect disallowed MIME type (“texthtml”) - Stack Overflow

So I have a 200 rewrite from domain1abc to my react app hosted on domain2<*>The app is hosted

So I have a 200 rewrite from domain1/abc/ to my react app hosted on domain2/<*>

The app is hosted on AWS Amplify and uses the following config:

Source address      Target address              Type  
/abc/<*>    /<*> 200 (Rewrite)  
/<*>            /index.html                 404 (Rewrite)

In my vite.config.js i defined the base as such:

export default defineConfig({
  base: '/abc/',
// ...
})

In my react router, I added /abc/:

<Routes>
  <Route
    path="/abc"
    element={<ABComponent receivedFailedMessages={setFailedMessages} startRecovery={startRecovery} />}
    />
    <Route path="*" element={<NotFound />} />

When trying to visit domain1/abc I get the following error and the page doesn't load correctly (also goes for css and such):

Loading module from “.js” was blocked because of a disallowed MIME type (“text/html”).

When visiting domain2 the assets are served from /abc/assets instead, but I still get the same error.

Build command for AWS deployments: "build": "vite build --config vite.config.js"

Base dir in amplify.yml:

artifacts:
    baseDirectory: dist

Built index.html contains /abc/ for linked js and css:

<!doctype html>
<html lang="en">
  <head>
// ...
    <script type="module" crossorigin src="/abc/assets/index-lZ-hm7W7.js"></script>
    <link rel="stylesheet" crossorigin href="/abc/assets/index-9of53dkd.css">
  </head>
// ...
  </body>
</html>

I've tried removing the base URL, or setting it to blank, changing redirect options in Amplify (source to /abc/<*>), changing router to serve / instead of /abc but nothing seems to work.

Removing base then loading the page on domain2/ loads the page, but the reverse proxy doesn't work, same error.

At this point I'm out of ideas, especially since this setup used to work a couple months ago without issue (base /abc and rewrite configured as above)

Expected result it the page loads normally from domain1/abc

Edit: It looks like there is something wrong with the reverse proxy setup When visiting domain1/abc it serves the index.html from the domain1 app, which means the assets have improper paths, and when visiting domain2 it serves the index.html from domain2.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744818146a4595451.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信