This commit is contained in:
Philipinho
2024-12-11 22:13:42 +00:00
parent 1302b1b602
commit 5506fe5e73
4 changed files with 36 additions and 2 deletions

View File

@ -1,5 +1,8 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, Param, Res } from '@nestjs/common';
import { AppService } from './app.service';
import { FastifyReply } from "fastify";
import { join } from 'path';
import * as fs from 'node:fs';
@Controller()
export class AppController {
@ -9,4 +12,27 @@ export class AppController {
getHello(): string {
return this.appService.getHello();
}
@Get('/share/:id')
getShare(@Res({ passthrough: false}) res: FastifyReply, @Param() params: any): string {
const clientDistPath = join(
__dirname,
'..',
'..',
'client/dist',
);
if (fs.existsSync(clientDistPath)) {
console.log('exists')
const indexFilePath = join(clientDistPath, 'index.html');
const stream = fs.createReadStream(indexFilePath);
console.log(params.id)
res.type('text/html').send(stream);
console.log('found');
return;
}
console.log('end')
return this.appService.getHello();
}
}

View File

@ -24,7 +24,7 @@ async function bootstrap() {
},
);
app.setGlobalPrefix('api');
app.setGlobalPrefix('api', { exclude: ['share/:id']});
const redisIoAdapter = new WsRedisIoAdapter(app);
await redisIoAdapter.connectToRedis();