feat: wire sidecar to platform — auth proxy with workspace subdomain, GraphQL proxy, health check

This commit is contained in:
2026-03-18 07:15:47 +05:30
parent d488d551ed
commit a42d479f06
9 changed files with 281 additions and 25 deletions

View File

@@ -0,0 +1,45 @@
import { Controller, Post, Req, Res, Logger, HttpException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import type { Request, Response } from 'express';
import axios from 'axios';
@Controller('graphql')
export class GraphqlProxyController {
private readonly logger = new Logger(GraphqlProxyController.name);
private readonly graphqlUrl: string;
constructor(private config: ConfigService) {
this.graphqlUrl = config.get<string>('platform.graphqlUrl')!;
}
@Post()
async proxy(@Req() req: Request, @Res() res: Response) {
const authHeader = req.headers.authorization;
if (!authHeader) {
throw new HttpException('Authorization header required', 401);
}
try {
const response = await axios.post(
this.graphqlUrl,
req.body,
{
headers: {
'Content-Type': 'application/json',
'Authorization': authHeader,
},
},
);
res.status(response.status).json(response.data);
} catch (error: any) {
if (error.response) {
res.status(error.response.status).json(error.response.data);
} else {
this.logger.error(`GraphQL proxy error: ${error.message}`);
throw new HttpException('Platform unreachable', 503);
}
}
}
}

View File

@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { GraphqlProxyController } from './graphql-proxy.controller';
@Module({
controllers: [GraphqlProxyController],
})
export class GraphqlProxyModule {}