Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect to new sandbox if the old one is not available #2187

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/ui5-proxy-middleware/src/base/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Filter, Options } from 'http-proxy-middleware';
import { createProxyMiddleware } from 'http-proxy-middleware';
import type { ClientRequest, IncomingMessage, ServerResponse } from 'http';
import type { Request } from 'express';
import type { ProxyConfig } from './types';
import {
proxyRequestHandler,
Expand Down Expand Up @@ -36,8 +37,8 @@ export const ui5Proxy = (config: ProxyConfig, options?: Options, filter?: Filter
proxyRequestHandler(proxyReq, res, etag, logger);
},
pathRewrite: { [config.path]: ui5Ver + config.path },
onProxyRes: (proxyRes: IncomingMessage): void => {
proxyResponseHandler(proxyRes, etag);
onProxyRes: (proxyRes: IncomingMessage, req: Request): void => {
proxyResponseHandler(proxyRes, req, etag);
},
onError: (
err: Error & { code?: string },
Expand Down
12 changes: 9 additions & 3 deletions packages/ui5-proxy-middleware/src/base/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ import type { Url } from 'url';
import { t } from '../i18n';

/**
* Handler for the proxy response event.
* Sets an Etag which will be used for re-validation of the cached UI5 sources.
* Handler for the proxy response event responsible for two tasks:
* 1. Sets an Etag which will be used for re-validation of the cached UI5 sources.
* 2. Redirects the request to the correct sandbox file if UI5 2.0 is used.
*
* @param proxyRes - proxy response object
* @param req - request object
* @param etag - ETag for the cached sources, normally the UI5 version
*/
export const proxyResponseHandler = (proxyRes: IncomingMessage, etag: string): void => {
export const proxyResponseHandler = (proxyRes: IncomingMessage, req: Request, etag: string): void => {
proxyRes.headers['Etag'] = etag;
proxyRes.headers['cache-control'] = 'no-cache';
if (proxyRes.statusCode === 404 && req.path.includes('/test-resources/sap/ushell/bootstrap/sandbox.js')) {
proxyRes.statusCode = 302;
proxyRes.headers['location'] = '/resources/sap/ushell/bootstrap/sandbox2.js';
}
};

/**
Expand Down
Loading