From e594074fdaa9871b540c3182328966192c72e500 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Mon, 27 Nov 2023 13:20:42 +0000 Subject: [PATCH] Server SPA from server * add /api prefix --- client/package.json | 4 ++-- client/src/components/navbar/user-button.tsx | 4 ++-- client/src/lib/api-client.ts | 2 +- server/package.json | 4 ++++ server/src/app.module.ts | 5 +++++ server/src/main.ts | 8 +++++++- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/client/package.json b/client/package.json index c2a9ec7c..71d8a3f5 100644 --- a/client/package.json +++ b/client/package.json @@ -3,10 +3,10 @@ "private": true, "version": "0.0.0", "scripts": { - "dev": "vite --port 3000", + "dev": "vite", "build": "tsc && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", - "preview": "vite preview --port 3000" + "preview": "vite preview" }, "dependencies": { "@hocuspocus/provider": "^2.8.1", diff --git a/client/src/components/navbar/user-button.tsx b/client/src/components/navbar/user-button.tsx index da847cd1..959666fa 100644 --- a/client/src/components/navbar/user-button.tsx +++ b/client/src/components/navbar/user-button.tsx @@ -17,11 +17,11 @@ export function UserButton() {
- {currentUser.user.name} + {currentUser?.user.name} - {currentUser.user.email} + {currentUser?.user.email}
diff --git a/client/src/lib/api-client.ts b/client/src/lib/api-client.ts index f1863222..8ba76632 100644 --- a/client/src/lib/api-client.ts +++ b/client/src/lib/api-client.ts @@ -3,7 +3,7 @@ import Cookies from "js-cookie"; import Routes from "@/lib/routes"; const api: AxiosInstance = axios.create({ - baseURL: import.meta.env.VITE_BACKEND_API_URL + baseURL: import.meta.env.VITE_BACKEND_API_URL + '/api' }); api.interceptors.request.use(config => { diff --git a/server/package.json b/server/package.json index 67cdddde..61ff7b0b 100644 --- a/server/package.json +++ b/server/package.json @@ -29,6 +29,7 @@ "dependencies": { "@aws-sdk/client-s3": "^3.456.0", "@aws-sdk/s3-request-presigner": "^3.456.0", + "@fastify/multipart": "^8.0.0", "@hocuspocus/server": "^2.8.1", "@hocuspocus/transformer": "^2.8.1", "@nestjs/common": "^10.2.10", @@ -38,6 +39,7 @@ "@nestjs/mapped-types": "^2.0.4", "@nestjs/platform-fastify": "^10.2.10", "@nestjs/platform-socket.io": "^10.2.10", + "@nestjs/serve-static": "^4.0.0", "@nestjs/typeorm": "^10.0.1", "@nestjs/websockets": "^10.2.10", "bcrypt": "^5.1.1", @@ -49,6 +51,8 @@ "pg": "^8.11.3", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1", + "sanitize-filename-ts": "^1.0.2", + "slugify": "^1.6.6", "socket.io": "^4.7.2", "typeorm": "^0.3.17", "uuid": "^9.0.1", diff --git a/server/src/app.module.ts b/server/src/app.module.ts index 4146677f..6b7a2a22 100644 --- a/server/src/app.module.ts +++ b/server/src/app.module.ts @@ -6,6 +6,8 @@ import { EnvironmentModule } from './environment/environment.module'; import { CollaborationModule } from './collaboration/collaboration.module'; import { DatabaseModule } from './database/database.module'; import { WsModule } from './ws/ws.module'; +import { ServeStaticModule } from '@nestjs/serve-static'; +import { join } from 'path'; @Module({ imports: [ @@ -14,6 +16,9 @@ import { WsModule } from './ws/ws.module'; DatabaseModule, CollaborationModule, WsModule, + ServeStaticModule.forRoot({ + rootPath: join(__dirname, '..', '..', 'client/dist'), + }), ], controllers: [AppController], providers: [AppService], diff --git a/server/src/main.ts b/server/src/main.ts index 169f67be..d8888402 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -6,6 +6,7 @@ import { } from '@nestjs/platform-fastify'; import { ValidationPipe } from '@nestjs/common'; import { TransformHttpResponseInterceptor } from './interceptors/http-response.interceptor'; +import fastifyMultipart from '@fastify/multipart'; async function bootstrap() { const app = await NestFactory.create( @@ -13,9 +14,13 @@ async function bootstrap() { new FastifyAdapter({ ignoreTrailingSlash: true, ignoreDuplicateSlashes: true, - }), + } as any), ); + app.setGlobalPrefix('api'); + + await app.register(fastifyMultipart); + app.useGlobalPipes( new ValidationPipe({ whitelist: true, @@ -29,4 +34,5 @@ async function bootstrap() { await app.listen(process.env.PORT || 3001); } + bootstrap();