mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-04-11 18:08:16 +00:00
feat: wire sidecar to platform — auth proxy with workspace subdomain, GraphQL proxy, health check
This commit is contained in:
45
src/graphql-proxy/graphql-proxy.controller.ts
Normal file
45
src/graphql-proxy/graphql-proxy.controller.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/graphql-proxy/graphql-proxy.module.ts
Normal file
7
src/graphql-proxy/graphql-proxy.module.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { GraphqlProxyController } from './graphql-proxy.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [GraphqlProxyController],
|
||||
})
|
||||
export class GraphqlProxyModule {}
|
||||
Reference in New Issue
Block a user