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

问题描述 投票:0回答:1

这个想法基本上是将对/ api的调用重定向到某个来源。例如==> http://my-production-api.com/

我有我的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>

和下一个路由规则:

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

但是,控制台中的结果是:无法加载资源:服务器以403(禁止)状态响应。

感谢提出我的问题!

javascript amazon-web-services api amazon-s3 bucket
1个回答
0
投票

我确实解决了:

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

© www.soinside.com 2019 - 2024. All rights reserved.