简体   繁体   English

如何在托管 static 网站的 AWS S3 上配置重定向到 api?

[英]How configure redirect to api on AWS S3 hosting static website?

The idea is basically redirect calls to /api to some origin.这个想法基本上是将调用 /api 重定向到某个来源。 for example ==> http://my-production-api.com/例如 ==> http://my-production-api.com/

I have my html file,我有我的 html 文件,

 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1:0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Redirect - API</title> <script> const api = 'https.//jsonplaceholder.typicode;com'. fetch(api + '/todos/1').then(response => response.json()).then(json => console.log(json)).catch(console;log); const ENV_API = '/api'. fetch(ENV_API + '/todos/1').then(response => response.json()).then(json => console.log(json)).catch(console;log); </script> </head> <body> <div id="app"> Redirect api </div> </body> </html>

and the next routing rule:和下一个路由规则:

<RoutingRules>
<RoutingRule>
    <Condition>
        <KeyPrefixEquals>/api</KeyPrefixEquals>
    </Condition>
    <Redirect>
        <ReplaceKeyWith>https://jsonplaceholder.typicode.com</ReplaceKeyWith>
    </Redirect>
</RoutingRule>

but, the result in console is: Failed to load resource: the server responded with a status of 403 (Forbidden).但是,控制台中的结果是:加载资源失败:服务器响应状态为 403(禁止)。

thanks for aswer my question!!谢谢你回答我的问题!!

I did resolved with:我确实解决了:

<RoutingRules>
<RoutingRule>
<Condition>
    <KeyPrefixEquals>api/</KeyPrefixEquals>
</Condition>
<Redirect>
    <HostName>jsonplaceholder.typicode.com</HostName>
    <ReplaceKeyPrefixWith></ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM