-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aed29e0
commit f42b737
Showing
2 changed files
with
40 additions
and
23 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
export const handler = async (event, context, callback) => { | ||
console.log(JSON.stringify(event)); | ||
|
||
// Extract the request from the CloudFront event that is sent to Lambda@Edge | ||
var request = event.Records[0].cf.request; | ||
|
||
const headers = request.headers; | ||
let tenantDomain = headers.host[0].value; | ||
|
||
console.log("Tenant domain: %s", tenantDomain); | ||
|
||
const workspaceRegex = /(\/products\/|\/addons\/|.aspx)/i; | ||
|
||
if (workspaceRegex.test(request.uri)) | ||
{ | ||
const newurl = `https://${tenantDomain.replace('onlyoffice.com', 'onlyoffice.co')}${request.uri}?${request.querystring}`; | ||
console.log("redirect to: %s", newurl); | ||
|
||
const response = { | ||
status: '302', | ||
statusDescription: 'Found', | ||
headers: { | ||
location: [{ | ||
key: 'Location', | ||
value: newurl, | ||
}], | ||
'cache-control': [{ // Add cache-control header | ||
key: 'Cache-Control', | ||
value: 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0' | ||
}], | ||
}, | ||
}; | ||
|
||
return callback(null, response); | ||
} | ||
|
||
return callback(null, request); | ||
} |