CloudFront Spa子Path,无S3托管

发布于 2025-02-08 16:43:53 字数 641 浏览 1 评论 0原文

我在S3中有一个水疗应用程序。 EC2中的API

我的CloudFront Logic如下:

  • /-Api-Origin
  • /front/* - S3-Bucket-Origin

Front具有其方式,例如

  • example.com/front/front/login/login
  • example.com/front/documents/
  • example.com/front/usersetting/

我设法通过托管代理来启动该应用程序。但是我想尝试在不启用S3托管的情况下实现此目标。

我尝试了什么:

为前部行为添加了CloudFront功能。

function handler(event) {
 var request = event.request;
 request.uri = request.uri.replace(/^\/[^/]*\//, "/");
 request.uri += '/front/index.html';

return request;

}

但是我得到404

,请告诉我如何正确实施。最好没有lambda(仅云范围功能)

I have a SPA app in S3. Api in EC2

My cloudfront logic is as follows:

  • / - api-origin
  • /front/* - s3-bucket-origin

The front has its ways, for example

  • example.com/front/User/Login
  • example.com/front/Documents/
  • example.com/front/UserSetting/

I managed to launch the application through s3 bucket hosting proxy. But I want to try to implement this without s3 hosting enabled.

What did I try:

Added cloudfront function for front behavior.

function handler(event) {
 var request = event.request;
 request.uri = request.uri.replace(/^\/[^/]*\//, "/");
 request.uri += '/front/index.html';

return request;

}

But I get 404

Please tell me how to implement this correctly. Preferably without Lambda (only cloudfront functions)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别在捏我脸啦 2025-02-15 16:43:53

为自己找到了解决方案。我不知道这有多正确,但它有效。

function handler(event) {
  var request = event.request;
  
  request.uri = request.uri.replace(/^\/[^/]*\//, "/");
  
  if (!request.uri.includes('.')) {
    request.uri = "/index.html";
  }

  return request;
}

我希望CloudFront功能不会花很多钱

Found a solution for myself. I don't know how correct this is, but it works.

function handler(event) {
  var request = event.request;
  
  request.uri = request.uri.replace(/^\/[^/]*\//, "/");
  
  if (!request.uri.includes('.')) {
    request.uri = "/index.html";
  }

  return request;
}

I hope cloudfront functions don't cost a lot of money

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文