Skip to content

Commit 5e524bc

Browse files
authored
Merge pull request #3173 from RedisInsight/feature/RI-5041-subpath-proxy
RI-5041: Static Subpath proxy support
2 parents 7950450 + 6bcc5a9 commit 5e524bc

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

redisinsight/api/config/default.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { join } from 'path';
22
import * as os from 'os';
3+
import { trim } from 'lodash';
34
import { version } from '../package.json';
45

56
const homedir = join(__dirname, '..');
@@ -15,15 +16,17 @@ const defaultsDir = process.env.RI_BUILD_TYPE === 'ELECTRON' && process['resourc
1516
? join(process['resourcesPath'], 'defaults')
1617
: join(__dirname, '..', 'defaults');
1718

18-
const customPluginsUri = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/plugins` : '/plugins';
19-
const staticUri = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/static` : '/static';
20-
const tutorialsUri = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/static/tutorials` : '/static/tutorials';
21-
const customTutorialsUri = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/static/custom-tutorials` : '/static/custom-tutorials';
22-
const contentUri = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/static/content` : '/static/content';
23-
const defaultPluginsUri = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/static/plugins` : '/static/plugins';
24-
const pluginsAssetsUri = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/static/resources/plugins` : '/static/resources/plugins';
19+
const proxyPath = trim(process.env.RI_PROXY_PATH, '/');
2520

26-
const socketPath = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/socket.io` : '/socket.io';
21+
const customPluginsUri = join('/', proxyPath, 'plugins');
22+
const staticUri = join('/', proxyPath, 'static');
23+
const tutorialsUri = join('/', proxyPath, 'static', 'tutorials');
24+
const customTutorialsUri = join('/', proxyPath, 'static', 'custom-tutorials');
25+
const contentUri = join('/', proxyPath, 'static', 'content');
26+
const defaultPluginsUri = join('/', proxyPath, 'static', 'plugins');
27+
const pluginsAssetsUri = join('/', proxyPath, 'static', 'resources', 'plugins');
28+
29+
const socketPath = join('/', proxyPath, 'socket.io');
2730
const dataDir = process.env.RI_BUILD_TYPE === 'ELECTRON' && process['resourcesPath']
2831
? join(process['resourcesPath'], 'data')
2932
: join(__dirname, '..', 'data');
@@ -65,7 +68,7 @@ export default {
6568
defaultPluginsUri,
6669
pluginsAssetsUri,
6770
base: process.env.RI_BASE || '/',
68-
proxyPath: process.env.RI_PROXY_PATH || '',
71+
proxyPath,
6972
secretStoragePassword: process.env.RI_SECRET_STORAGE_PASSWORD,
7073
encryptionKey: process.env.RI_ENCRYPTION_KEY,
7174
tlsCert: process.env.RI_SERVER_TLS_CERT,

redisinsight/api/src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { join } from 'path';
12
import 'dotenv/config';
23
import { NestFactory } from '@nestjs/core';
34
import { SwaggerModule } from '@nestjs/swagger';
@@ -46,7 +47,7 @@ export default async function bootstrap(apiPort?: number): Promise<IApp> {
4647
if (process.env.RI_APP_TYPE !== 'electron') {
4748
let prefix = serverConfig.globalPrefix;
4849
if (serverConfig.proxyPath) {
49-
prefix = `${serverConfig.proxyPath}/${prefix}`;
50+
prefix = join(serverConfig.proxyPath, prefix);
5051
}
5152

5253
app.setGlobalPrefix(prefix, { exclude: ['/'] });

redisinsight/api/src/middleware/subpath-proxy.middleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { NestMiddleware, Injectable } from '@nestjs/common';
22
import { Request, Response, NextFunction } from 'express';
3+
import { trim } from 'lodash';
34
import * as fs from 'fs';
45

56
@Injectable()
67
export default class SubpathProxyMiddleware implements NestMiddleware {
78
async use(req: Request, res: Response, next: NextFunction) {
89
const originalSendFile = res.sendFile;
9-
const proxyPath = process.env.RI_PROXY_PATH || '';
10+
const proxyPath = trim(process.env.RI_PROXY_PATH, '/');
1011
res.sendFile = function (this: Response, path: string, options: any, callback?: (err?: Error) => void) {
1112
if (path.endsWith('.html')) {
1213
let content = fs.readFileSync(path, 'utf8');

0 commit comments

Comments
 (0)