Configuring a subdirectory with AWS using CloudFront and Route 53
Host your documentation with a /docs subdirectory using AWS CloudFront and Route 53.
3
Update the Lambda function code
export const handler = async (event) => {
const request = event.Records[0].cf.request;
// update if your subdirectory is not /docs
const subdirectory = '/docs';
// update with your proxy URL below
const target = new URL('<proxy URL you got from GitBook>');
// rewrite: /docs* -> proxy.gitbook.site
if (request.uri.startsWith(subdirectory)) {
request.uri = target.pathname + request.uri.substring(subdirectory.length);
// Remove trailing slash if present
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
Troubleshooting
Last updated
Was this helpful?