Server SPA from server

* add /api prefix
This commit is contained in:
Philipinho 2023-11-27 13:20:42 +00:00
parent 544e34475b
commit e594074fda
6 changed files with 21 additions and 6 deletions

View File

@ -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",

View File

@ -17,11 +17,11 @@ export function UserButton() {
<div style={{ flex: 1 }}>
<Text size="sm" fw={500}>
{currentUser.user.name}
{currentUser?.user.name}
</Text>
<Text c="dimmed" size="xs">
{currentUser.user.email}
{currentUser?.user.email}
</Text>
</div>

View File

@ -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 => {

View File

@ -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",

View File

@ -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],

View File

@ -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<NestFastifyApplication>(
@ -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();