Browse Source

fix: set socket path and namespace by environment variables

pull/6157/head
lolgopher 1 year ago
parent
commit
f554eab3f1
  1. 1
      packages/nc-gui/plugins/jobs.ts
  2. 5
      packages/nc-gui/plugins/tele.ts
  3. 2
      packages/nocodb/src/gateways/socket.gateway.ts
  4. 3
      packages/nocodb/src/modules/jobs/jobs.gateway.ts

1
packages/nc-gui/plugins/jobs.ts

@ -16,6 +16,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
socket = io(`${url.href}jobs`, {
extraHeaders: { 'xc-auth': token },
path: `${url.pathname}socket.io`,
})
socket.on('connect_error', (e) => {

5
packages/nc-gui/plugins/tele.ts

@ -16,10 +16,11 @@ export default defineNuxtPlugin(async (nuxtApp) => {
try {
if (socket) socket.disconnect()
const url = new URL(appInfo.ncSiteUrl, window.location.href.split(/[?#]/)[0]).href
const url = new URL(appInfo.ncSiteUrl, window.location.href.split(/[?#]/)[0])
socket = io(url, {
socket = io(url.href, {
extraHeaders: { 'xc-auth': token },
path: `${url.pathname}socket.io`,
})
socket.on('connect_error', () => {

2
packages/nocodb/src/gateways/socket.gateway.ts

@ -14,12 +14,14 @@ function getHash(str) {
return crypto.createHash('md5').update(str).digest('hex');
}
const url = new URL(process.env.NC_PUBLIC_URL || `http://localhost:${process.env.PORT}/`)
@WebSocketGateway({
cors: {
origin: '*',
allowedHeaders: ['xc-auth'],
credentials: true,
},
namespace: url.pathname,
})
@Injectable()
export class SocketGateway implements OnModuleInit {

3
packages/nocodb/src/modules/jobs/jobs.gateway.ts

@ -14,13 +14,14 @@ import { JobEvents } from '../../interface/Jobs';
import type { OnModuleInit } from '@nestjs/common';
import type { JobStatus } from '../../interface/Jobs';
const url = new URL(process.env.NC_PUBLIC_URL || `http://localhost:${process.env.PORT}/`)
@WebSocketGateway({
cors: {
origin: '*',
allowedHeaders: ['xc-auth'],
credentials: true,
},
namespace: 'jobs',
namespace: `${url.pathname}jobs`,
})
export class JobsGateway implements OnModuleInit {
constructor(@Inject('JobsService') private readonly jobsService) {}

Loading…
Cancel
Save