Skip to content

Commit ddd63eb

Browse files
committed
docker-testing
2 parents a24d3e0 + 3bc28eb commit ddd63eb

File tree

26 files changed

+163
-26
lines changed

26 files changed

+163
-26
lines changed

configs/webpack.config.web.common.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
import path from 'path';
55
import webpack from 'webpack';
6-
import HtmlWebpackPlugin from 'html-webpack-plugin';
76
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
87
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
98
import webpackPaths from './webpack.paths';
@@ -68,8 +67,6 @@ export default {
6867
'window.app.config.apiPort': JSON.stringify('5540'),
6968
}),
7069

71-
new HtmlWebpackPlugin({ template: 'index.html.ejs' }),
72-
7370
new MonacoWebpackPlugin({ languages: ['json', 'javascript', 'typescript'], features: ['!rename'] }),
7471

7572
new webpack.IgnorePlugin({

configs/webpack.config.web.dev.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import webpack from 'webpack';
1111
import { merge } from 'webpack-merge';
1212
import { toString } from 'lodash'
1313
import commonConfig from './webpack.config.web.common';
14+
import HtmlWebpackPlugin from 'html-webpack-plugin';
1415

1516
function employCache(loaders) {
1617
return ['cache-loader'].concat(loaders);
@@ -198,7 +199,10 @@ const configuration: webpack.Configuration = {
198199
new webpack.HotModuleReplacementPlugin({
199200
multiStep: true,
200201
}),
201-
202+
new HtmlWebpackPlugin({
203+
inject: 'head',
204+
template: 'index.html.ejs',
205+
}),
202206
new webpack.NoEmitOnErrorsPlugin(),
203207

204208
/**

configs/webpack.config.web.prod.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
88
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
99
import commonConfig from './webpack.config.web.common';
1010
import DeleteDistWeb from '../scripts/DeleteDistWeb';
11+
import HtmlWebpackPlugin from 'html-webpack-plugin';
1112

1213
DeleteDistWeb();
1314

@@ -72,6 +73,11 @@ const configuration: webpack.Configuration = {
7273
filename: '[name].[fullhash].css',
7374
chunkFilename: '[id].[fullhash].css',
7475
}),
76+
new HtmlWebpackPlugin({
77+
inject: 'head',
78+
template: 'index.html.ejs',
79+
publicPath: '{{ RIPROXYPATH }}',
80+
}),
7581

7682
new webpack.EnvironmentPlugin({
7783
NODE_ENV: 'production',

redisinsight/api/config/default.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ const defaultsDir = process.env.RI_BUILD_TYPE === 'ELECTRON' && process['resourc
1515
? join(process['resourcesPath'], 'defaults')
1616
: join(__dirname, '..', 'defaults');
1717

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';
25+
26+
const socketPath = process.env.RI_PROXY_PATH ? `/${process.env.RI_PROXY_PATH}/socket.io` : '/socket.io';
27+
1828
export default {
1929
dir_path: {
2030
tmpDir: os.tmpdir(),
@@ -43,14 +53,15 @@ export default {
4353
port: parseInt(process.env.RI_APP_PORT, 10) || 5540,
4454
docPrefix: 'api/docs',
4555
globalPrefix: 'api',
46-
customPluginsUri: '/plugins',
47-
staticUri: '/static',
48-
tutorialsUri: '/static/tutorials',
49-
customTutorialsUri: '/static/custom-tutorials',
50-
contentUri: '/static/content',
51-
defaultPluginsUri: '/static/plugins',
52-
pluginsAssetsUri: '/static/resources/plugins',
56+
customPluginsUri,
57+
staticUri,
58+
tutorialsUri,
59+
customTutorialsUri,
60+
contentUri,
61+
defaultPluginsUri,
62+
pluginsAssetsUri,
5363
base: process.env.RI_BASE || '/',
64+
proxyPath: process.env.RI_PROXY_PATH || '',
5465
secretStoragePassword: process.env.RI_SECRET_STORAGE_PASSWORD,
5566
encryptionKey: process.env.RI_ENCRYPTION_KEY,
5667
tlsCert: process.env.RI_SERVER_TLS_CERT,
@@ -65,6 +76,7 @@ export default {
6576
sockets: {
6677
cors: process.env.RI_SOCKETS_CORS ? process.env.RI_SOCKETS_CORS === 'true' : false,
6778
serveClient: process.env.RI_SOCKETS_SERVE_CLIENT ? process.env.RI_SOCKETS_SERVE_CLIENT === 'true' : false,
79+
path: socketPath,
6880
},
6981
db: {
7082
database: join(homedir, 'redisinsight.db'),

redisinsight/api/src/app.module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { ProfilerModule } from './modules/profiler/profiler.module';
3030
import { CliModule } from './modules/cli/cli.module';
3131
import { StaticsManagementModule } from './modules/statics-management/statics-management.module';
3232
import { ExcludeRouteMiddleware } from './middleware/exclude-route.middleware';
33+
import SubpathProxyMiddleware from './middleware/subpath-proxy.middleware';
3334
import { routes } from './app.routes';
3435

3536
const SERVER_CONFIG = config.get('server') as Config['server'];
@@ -65,6 +66,10 @@ const PATH_CONFIG = config.get('dir_path') as Config['dir_path'];
6566
ServeStaticModule.forRoot({
6667
rootPath: join(__dirname, '..', '..', '..', 'ui', 'dist'),
6768
exclude: ['/api/**', `${SERVER_CONFIG.customPluginsUri}/**`, `${SERVER_CONFIG.staticUri}/**`],
69+
serveRoot: SERVER_CONFIG.proxyPath ? `/${SERVER_CONFIG.proxyPath}` : '',
70+
serveStaticOptions: {
71+
index: false,
72+
},
6873
}),
6974
]
7075
: []),
@@ -105,6 +110,10 @@ export class AppModule implements OnModuleInit, NestModule {
105110
}
106111

107112
configure(consumer: MiddlewareConsumer) {
113+
consumer
114+
.apply(SubpathProxyMiddleware)
115+
.forRoutes('*');
116+
108117
consumer
109118
.apply(SingleUserAuthMiddleware)
110119
.exclude(...SERVER_CONFIG.excludeAuthRoutes)

redisinsight/api/src/main.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ export default async function bootstrap(apiPort?: number): Promise<IApp> {
4242
app.use(bodyParser.json({ limit: '512mb' }));
4343
app.use(bodyParser.urlencoded({ limit: '512mb', extended: true }));
4444
app.enableCors();
45-
app.setGlobalPrefix(serverConfig.globalPrefix);
4645

4746
if (process.env.RI_APP_TYPE !== 'electron') {
47+
let prefix = serverConfig.globalPrefix;
48+
if (serverConfig.proxyPath) {
49+
prefix = `${serverConfig.proxyPath}/${prefix}`;
50+
}
51+
52+
app.setGlobalPrefix(prefix, { exclude: ['/'] });
53+
4854
SwaggerModule.setup(
4955
serverConfig.docPrefix,
5056
app,
@@ -58,6 +64,7 @@ export default async function bootstrap(apiPort?: number): Promise<IApp> {
5864
},
5965
);
6066
} else {
67+
app.setGlobalPrefix(serverConfig.globalPrefix);
6168
app.useWebSocketAdapter(new WindowsAuthAdapter(app));
6269
}
6370

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { NestMiddleware, Injectable } from '@nestjs/common';
2+
import { Request, Response, NextFunction } from 'express';
3+
import * as fs from 'fs';
4+
5+
@Injectable()
6+
export default class SubpathProxyMiddleware implements NestMiddleware {
7+
async use(req: Request, res: Response, next: NextFunction) {
8+
const originalSendFile = res.sendFile;
9+
const proxyPath = process.env.RI_PROXY_PATH || '';
10+
res.sendFile = function (this: Response, path: string, options: any, callback?: (err?: Error) => void) {
11+
if (path.endsWith('.html')) {
12+
let content = fs.readFileSync(path, 'utf8');
13+
const regex = /{{ RIPROXYPATH }}/g;
14+
content = content.replace(regex, proxyPath);
15+
res.send(content);
16+
return;
17+
}
18+
originalSendFile.call(this, path, options, callback);
19+
};
20+
21+
next();
22+
}
23+
}

redisinsight/api/src/modules/bulk-actions/bulk-actions.gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const SOCKETS_CONFIG = config.get('sockets');
2222

2323
@UsePipes(new ValidationPipe({ transform: true }))
2424
@UseFilters(AckWsExceptionFilter)
25-
@WebSocketGateway({ namespace: 'bulk-actions', cors: SOCKETS_CONFIG.cors, serveClient: SOCKETS_CONFIG.serveClient })
25+
@WebSocketGateway({ path: SOCKETS_CONFIG.path, namespace: 'bulk-actions', cors: SOCKETS_CONFIG.cors, serveClient: SOCKETS_CONFIG.serveClient })
2626
export class BulkActionsGateway implements OnGatewayConnection, OnGatewayDisconnect {
2727
@WebSocketServer() wss: Server;
2828

redisinsight/api/src/modules/cloud/job/cloud-job.gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { CloudJobInfo } from 'src/modules/cloud/job/models';
1818

1919
const SOCKETS_CONFIG = config.get('sockets');
2020

21-
@WebSocketGateway({ cors: SOCKETS_CONFIG.cors, serveClient: SOCKETS_CONFIG.serveClient })
21+
@WebSocketGateway({ path: SOCKETS_CONFIG.path, cors: SOCKETS_CONFIG.cors, serveClient: SOCKETS_CONFIG.serveClient })
2222
export class CloudJobGateway {
2323
@WebSocketServer() wss: Server;
2424

redisinsight/api/src/modules/database-recommendation/database-recommendation.gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212

1313
const SOCKETS_CONFIG = config.get('sockets');
1414

15-
@WebSocketGateway({ cors: SOCKETS_CONFIG.cors, serveClient: SOCKETS_CONFIG.serveClient })
15+
@WebSocketGateway({ path: SOCKETS_CONFIG.path, cors: SOCKETS_CONFIG.cors, serveClient: SOCKETS_CONFIG.serveClient })
1616
export class DatabaseRecommendationGateway {
1717
@WebSocketServer() wss: Server;
1818

0 commit comments

Comments
 (0)