From 215efc067814700a253d1c6c235b63ed9ffdd26a Mon Sep 17 00:00:00 2001 From: Serge Malkin Date: Tue, 19 Dec 2023 09:58:54 +0300 Subject: [PATCH] Update index.mjs --- docspace-reverse-proxy/index.mjs | 43 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/docspace-reverse-proxy/index.mjs b/docspace-reverse-proxy/index.mjs index a5b6ca3..c49cd68 100644 --- a/docspace-reverse-proxy/index.mjs +++ b/docspace-reverse-proxy/index.mjs @@ -1,23 +1,30 @@ 'use strict'; -// Redirect from DS to WS if match -const workspaceRegex = /(\/products\/|\/addons\/|.aspx)/i; +export const handler = async (event, context, callback) => { + console.log(JSON.stringify(event)); -if (workspaceRegex.test(request.uri)) -{ - const newurl = `https://${tenantDomain.replace('onlyoffice.io', 'teamlab.info')}${request.uri}?${request.querystring}`; - console.log("redirect to: %s", newurl); - const response = { - status: '302', - statusDescription: 'Found', - headers: { - location: [{ - key: 'Location', - value: newurl, - }], - }, - }; + // Extract the request from the CloudFront event that is sent to Lambda@Edge + var request = event.Records[0].cf.request; - return callback(null, response); + // Redirect from DS to WS if match + const workspaceRegex = /(\/products\/|\/addons\/|.aspx)/i; -} \ No newline at end of file + if (workspaceRegex.test(request.uri)) + { + const newurl = `https://${tenantDomain.replace('onlyoffice.io', 'teamlab.info')}${request.uri}?${request.querystring}`; + console.log("redirect to: %s", newurl); + const response = { + status: '302', + statusDescription: 'Found', + headers: { + location: [{ + key: 'Location', + value: newurl, + }], + }, + }; + + return callback(null, response); + + } +};