使用 AWS(CloudFront 和 Route 53)配置子目录
使用 AWS CloudFront 和 Route 53 将您的文档托管在 /docs 子目录下。
3
更新 Lambda 函数代码
export const handler = async (event) => {
const request = event.Records[0].cf.request;
// 如果你的子目录不是 /docs,请更新此处
const subdirectory = '/docs';
// 在下面用你的代理 URL 更新
const target = new URL('<proxy URL you got from GitBook>');
// 重写:/docs* -> proxy.gitbook.site
if (request.uri.startsWith(subdirectory)) {
request.uri = target.pathname + request.uri.substring(subdirectory.length);
// 如有尾部斜杠则移除
if (request.uri.endsWith('/')) {
request.uri = request.uri.slice(0, -1);
}
request.origin = {
custom: {
domainName: target.host,
port: 443,
protocol: 'https',
path: '',
sslProtocols: ['TLSv1.2'],
readTimeout: 30,
keepaliveTimeout: 5,
customHeaders: {},
},
};
request.headers['host'] = [{ key: 'host', value: target.host }];
request.headers['x-forwarded-host'] = [{ key: 'x-forwarded-host', value: target.host }];
}
return request;
};4
故障排除
最后更新于
这有帮助吗?