Office IP Testing
warning
This section is not applicable in SSG mode. Using this strategy on the server breaks HTML cache on your page.
Using isOfficeIP(headers)
You can use this utility inside Page.routeProtection (for pages with getInitialProps), or your getServerSideProps data-fetching functions.
Example with routeProtection
import { TravelokaPageComponent } from '@traveloka/core';
const Page: TravelokaPageComponent = props => {
return <div />;
};
Page.routeProtection = routeCtx => {
const { headers } = routeCtx;
const isOfficeIp = isOfficeIP(headers);
// Allow access form office IP
if (isOfficeIp) {
return { status: 200 };
}
// Redirect elsewhere if it's not from office IP
return {
path: `/`,
status: 302,
};
};
Allowing Lighhouse Benchmarking
To allow lighthouse to reliably benchmark your page, you can add lighthouse query string like the following.
Page.routeProtection = routeCtx => {
const { headers, currentRoute } = routeCtx;
const isOfficeIp = isOfficeIP(routeCtx);
// Please check if this hash value is up-to-date
const isInternalLighthouse =
currentRoute?.query?.lighthouse === 'Saowdt6tUvEW8ejPsf7m';
// Allow test from lighthouse
if (isInternalLighthouse) {
return { status: 200 };
}
if (isOfficeIp) {
return { status: 200 };
}
return {
path: `/`,
status: 302,
};
};