Skip to content

Commit

Permalink
Merge pull request #38 from ToolJet/ecs-support
Browse files Browse the repository at this point in the history
ALB/NLB Support
  • Loading branch information
akshaysasidrn committed Aug 31, 2022
2 parents 6473913 + 5dc2219 commit ab4598f
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion frontend/src/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class App extends React.Component {
link.rel = 'icon';
document.getElementsByTagName('head')[0].appendChild(link);
}
link.href = favicon_url ? favicon_url : '/assets/images/logo.svg';
link.href = favicon_url ? favicon_url : 'assets/images/logo.svg';
document.title = `${retrieveWhiteLabelText()} - Dashboard`;
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/HomePage/AppCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ToolTip } from '@/_components';
import useHover from '@/_hooks/useHover';
import configs from './Configs/AppIcon.json';
import { Link } from 'react-router-dom';
import urlJoin from 'url-join';

const { defaultIcon } = configs;

Expand Down Expand Up @@ -131,7 +132,7 @@ export default function AppCard({
disabled={app?.current_version_id === null || app?.is_maintenance_on}
onClick={() => {
if (app?.current_version_id) {
window.open(`/applications/${app.slug}`);
window.open(urlJoin(window.public_config?.TOOLJET_HOST, `/applications/${app.slug}`));
} else {
history.push(app?.current_version_id ? `/applications/${app.slug}` : '');
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/ManageSSO/OpenId.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function OpenId({ settings, updateData }) {
<label className="form-label">
Client Secret
<small className="text-green mx-2">
<img className="mx-2 encrypted-icon" src="/assets/images/icons/padlock.svg" width="12" height="12" />
<img className="mx-2 encrypted-icon" src="assets/images/icons/padlock.svg" width="12" height="12" />
Encrypted
</small>
</label>
Expand Down Expand Up @@ -147,7 +147,7 @@ export function OpenId({ settings, updateData }) {
{configId && (
<div className="form-group mb-3">
<label className="form-label">Redirect URL</label>
<div>{`${window.location.protocol}//${window.location.host}/sso/openid/${configId}`}</div>
<div>{`${window.public_config?.TOOLJET_HOST}/sso/openid/${configId}`}</div>
</div>
)}
<div className="form-footer">
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/SignupPage/SignupPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ class SignupPage extends React.Component {
{this.ssoConfigs.configs?.openid?.enabled && (
<OidcSSOLoginButton text="Sign up with" configs={this.ssoConfigs.configs?.openid?.configs} />
)}
<div className="mt-2 separator">
<h2>
<span>OR</span>
</h2>
</div>
{(this.ssoConfigs.configs?.git?.enabled ||
this.ssoConfigs.configs?.google?.enabled ||
this.ssoConfigs.configs?.openid?.enabled) && (
<div className="mt-2 separator">
<h2>
<span>OR</span>
</h2>
</div>
)}
</div>
)}
<div className="mb-3">
Expand Down
2 changes: 2 additions & 0 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ if (process.env.SERVE_CLIENT !== 'false') {

imports.unshift(
ServeStaticModule.forRoot({
// Have to remove trailing slash of SUB_PATH.
serveRoot: process.env.SUB_PATH === undefined ? '' : process.env.SUB_PATH.replace(/\/$/, ''),
rootPath: join(__dirname, '../../../', 'frontend/build'),
})
);
Expand Down
5 changes: 5 additions & 0 deletions server/src/controllers/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ export class AppController {
async healthCheck(@Request() req) {
return { works: 'yeah' };
}

@Get('/')
async rootPage(@Request() req) {
return { message: 'Instance seems healthy but this is probably not the right URL to access.' };
}
}
3 changes: 2 additions & 1 deletion server/src/events/events.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {
import { Server } from 'ws';
import { AuthService } from 'src/services/auth.service';
import { isEmpty } from 'lodash';
import { maybeSetSubPath } from '../helpers/utils.helper';

@WebSocketGateway({ path: '/ws' })
@WebSocketGateway({ path: maybeSetSubPath('/ws') })
export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
constructor(private authService: AuthService) {}
@WebSocketServer()
Expand Down
5 changes: 3 additions & 2 deletions server/src/events/yjs.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import http from 'http';
import { WebSocketGateway, WebSocketServer, OnGatewayConnection, OnGatewayDisconnect } from '@nestjs/websockets';
import { Server } from 'ws';
import { AuthService } from 'src/services/auth.service';
import { isEmpty } from 'lodash';
import { setupWSConnection, setPersistence } from 'y-websocket/bin/utils';
import { RedisPubSub } from '../helpers/redis';
import { maybeSetSubPath } from '../helpers/utils.helper';
import { isEmpty } from 'lodash';

// TODO: Mock redis for test env
if (process.env.NODE_ENV !== 'test') {
Expand Down Expand Up @@ -34,7 +35,7 @@ if (process.env.NODE_ENV !== 'test') {
});
}

@WebSocketGateway({ path: '/yjs' })
@WebSocketGateway({ path: maybeSetSubPath('/yjs') })
export class YjsGateway implements OnGatewayConnection, OnGatewayDisconnect {
constructor(private authService: AuthService) {}
@WebSocketServer()
Expand Down
13 changes: 13 additions & 0 deletions server/src/helpers/utils.helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QueryError } from 'src/modules/data_sources/query.errors';
import * as sanitizeHtml from 'sanitize-html';
import { EntityManager, getManager } from 'typeorm';
import { isEmpty } from 'lodash';

export function parseJson(jsonString: string, errorMessage?: string): object {
try {
Expand All @@ -10,6 +11,18 @@ export function parseJson(jsonString: string, errorMessage?: string): object {
}
}

export function maybeSetSubPath(path) {
const hasSubPath = process.env.SUB_PATH !== undefined;
const urlPrefix = hasSubPath ? process.env.SUB_PATH : '';

if (isEmpty(urlPrefix)) {
return path;
}

const pathWithoutLeadingSlash = path.replace(/^\/+/, '');
return urlPrefix + pathWithoutLeadingSlash;
}

export async function cacheConnection(dataSourceId: string, connection: any): Promise<any> {
const updatedAt = new Date();
globalThis.CACHED_CONNECTIONS[dataSourceId] = { connection, updatedAt };
Expand Down
17 changes: 15 additions & 2 deletions server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as helmet from 'helmet';
import { Logger } from 'nestjs-pino';
import { urlencoded, json } from 'express';
import { AllExceptionsFilter } from './all-exceptions-filter';
import { ValidationPipe } from '@nestjs/common';
import { RequestMethod, ValidationPipe } from '@nestjs/common';
import * as cookieParser from 'cookie-parser';
import { ConfigService } from '@nestjs/config';
import { bootstrap as globalAgentBootstrap } from 'global-agent';
Expand All @@ -33,7 +33,20 @@ async function bootstrap() {
app.useGlobalFilters(new AllExceptionsFilter(app.get(Logger)));
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
app.useWebSocketAdapter(new WsAdapter(app));
app.setGlobalPrefix('api');

const hasSubPath = process.env.SUB_PATH !== undefined;
const UrlPrefix = hasSubPath ? process.env.SUB_PATH : '';

// Exclude these endpoints from prefix. These endpoints are required for health checks.
const pathsToExclude = [];
if (hasSubPath) {
pathsToExclude.push({ path: 'health', method: RequestMethod.GET });
pathsToExclude.push({ path: '/', method: RequestMethod.GET });
}

app.setGlobalPrefix(UrlPrefix + 'api', {
exclude: pathsToExclude,
});
app.enableCors({
origin: true,
credentials: true,
Expand Down

0 comments on commit ab4598f

Please sign in to comment.