Skip to content

Commit

Permalink
ADD viewer request function
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroslavPshenichnikov committed Dec 19, 2023
1 parent aed29e0 commit f42b737
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
23 changes: 0 additions & 23 deletions docspace-reverse-proxy/index.mjs

This file was deleted.

40 changes: 40 additions & 0 deletions docspace-viewer-request/index.mjs
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);
}

0 comments on commit f42b737

Please sign in to comment.