【问题标题】:AWS-S3 and AWS-CloudFront With React routes, multi applicationAWS-S3 和 AWS-CloudFront 与 React 路由,多应用程序
【发布时间】:2021-05-14 15:11:00
【问题描述】:

我有以下场景。

  • S3 存储桶和多个目录,每个 React 应用一个目录
  • 每个 React 应用程序的所有路径都以 s3 存储桶中托管的目录名称开头

例如:

S3 目录

|--/
   |--/first-app/
   |--/second-app/

反应first-app的路由

const routes = [
  {
    path: '/',
    component: Empty,
    exact: true,
  },
  {
    path: '/first-app',
    component: Layout,
    routes: [
      { path: '/first-app/create', component: CreateCommponent},
      { path: '/first-app/login', component: Login },
      { path: '/first-app/logout', component: Logout },
    ],
  },
]

反应second-app的路由

const routes = [
  {
    path: '/',
    component: Empty,
    exact: true,
  },
  {
    path: '/second-app',
    component: Layout,
    routes: [
      { path: '/second-app/create', component: OtherComponent},
      { path: '/second-app/login', component: Login },
      { path: '/second-app/logout', component: Logout },
    ],
  },
]

如何让 cloudFront 独立为每个目录中的每个应用程序服务,但在同一个域下?

https://my.domain.com/first-app >> service react application 中间 index.html of first-app

https://my.domain.com/second-app>> 服务于第二个app的react应用中间index.html

【问题讨论】:

    标签: reactjs amazon-web-services amazon-s3 react-router amazon-cloudfront


    【解决方案1】:

    您可以使用 Lambda@Edge 执行此操作,以便在将请求发送到存储桶之前操纵请求参数。这是一个类似的例子:here

    【讨论】:

    • 这会增加运营成本。
    • 肯定没有更好的解决方案
    猜你喜欢
    • 2021-05-03
    • 2014-10-14
    • 2021-09-08
    • 2017-07-24
    • 2017-11-12
    • 2021-01-29
    • 1970-01-01
    • 2019-01-30
    • 2020-04-10
    相关资源
    最近更新 更多