File tree 4 files changed +50
-11
lines changed
4 files changed +50
-11
lines changed Original file line number Diff line number Diff line change 34
34
"@nestjs/jwt" : " ^10.0.3" ,
35
35
"@nestjs/passport" : " ^9.0.3" ,
36
36
"@nestjs/platform-express" : " ^9.0.0" ,
37
- "@nestjs/serve-static" : " ^3 .0.0 " ,
37
+ "@nestjs/serve-static" : " ^4 .0.1 " ,
38
38
"@nestjs/terminus" : " ^9.2.2" ,
39
39
"@nestjs/typeorm" : " ^10.0.0" ,
40
40
"@nivo/calendar" : " ^0.84.0" ,
Original file line number Diff line number Diff line change @@ -5,10 +5,29 @@ declare global {
5
5
}
6
6
}
7
7
8
+ const getDefaultUrl = ( ) => {
9
+ if (
10
+ window . location . hostname === 'localhost' ||
11
+ window . location . hostname === '127.0.0.1'
12
+ ) {
13
+ // In development environment front and backend usually run on seperate ports
14
+ // we set the default value to localhost:3000.
15
+ // It dev context, we use env vars to overwrite it
16
+ return 'http://localhost:3000' ;
17
+ } else {
18
+ // Outside of localhost we assume that they run on the same port
19
+ // because the backend will serve the frontend
20
+ // It prod context, we use env-config.js + window var to ovewrite it
21
+ return `${ window . location . protocol } //${ window . location . hostname } ${
22
+ window . location . port ? `:${ window . location . port } ` : ''
23
+ } `;
24
+ }
25
+ } ;
26
+
8
27
export const REACT_APP_SERVER_BASE_URL =
9
28
window . _env_ ?. REACT_APP_SERVER_BASE_URL ||
10
29
process . env . REACT_APP_SERVER_BASE_URL ||
11
- 'http://localhost:3000' ;
30
+ getDefaultUrl ( ) ;
12
31
13
32
export const REACT_APP_SERVER_AUTH_URL =
14
33
window . _env_ ?. REACT_APP_SERVER_AUTH_URL ||
Original file line number Diff line number Diff line change 1
- import { Module } from '@nestjs/common' ;
1
+ import { DynamicModule , Module } from '@nestjs/common' ;
2
2
import { GraphQLModule } from '@nestjs/graphql' ;
3
3
import { ConfigModule } from '@nestjs/config' ;
4
+ import { ServeStaticModule } from '@nestjs/serve-static' ;
5
+
6
+ import { existsSync } from 'fs' ;
7
+ import { join } from 'path' ;
4
8
5
9
import { YogaDriver , YogaDriverConfig } from '@graphql-yoga/nestjs' ;
6
10
@@ -26,6 +30,22 @@ import { GraphQLConfigModule } from './graphql-config/graphql-config.module';
26
30
IntegrationsModule ,
27
31
CoreModule ,
28
32
WorkspaceModule ,
33
+ ...AppModule . getConditionalModules ( ) ,
29
34
] ,
30
35
} )
31
- export class AppModule { }
36
+ export class AppModule {
37
+ private static getConditionalModules ( ) : DynamicModule [ ] {
38
+ const modules : DynamicModule [ ] = [ ] ;
39
+ const frontPath = join ( __dirname , '..' , 'front' ) ;
40
+
41
+ if ( existsSync ( frontPath ) ) {
42
+ modules . push (
43
+ ServeStaticModule . forRoot ( {
44
+ rootPath : frontPath ,
45
+ } ) ,
46
+ ) ;
47
+ }
48
+
49
+ return modules ;
50
+ }
51
+ }
Original file line number Diff line number Diff line change @@ -8134,15 +8134,15 @@ __metadata:
8134
8134
languageName: node
8135
8135
linkType: hard
8136
8136
8137
- "@nestjs/serve-static@npm:^3 .0.0 ":
8138
- version: 3 .0.1
8139
- resolution: "@nestjs/serve-static@npm:3 .0.1"
8137
+ "@nestjs/serve-static@npm:^4 .0.1 ":
8138
+ version: 4 .0.1
8139
+ resolution: "@nestjs/serve-static@npm:4 .0.1"
8140
8140
dependencies:
8141
8141
path-to-regexp: "npm:0.2.5"
8142
8142
peerDependencies:
8143
8143
"@fastify/static": ^6.5.0
8144
- "@nestjs/common": ^9.0.0
8145
- "@nestjs/core": ^9.0.0
8144
+ "@nestjs/common": ^9.0.0 || ^10.0.0
8145
+ "@nestjs/core": ^9.0.0 || ^10.0.0
8146
8146
express: ^4.18.1
8147
8147
fastify: ^4.7.0
8148
8148
peerDependenciesMeta:
@@ -8152,7 +8152,7 @@ __metadata:
8152
8152
optional: true
8153
8153
fastify:
8154
8154
optional: true
8155
- checksum: 70d47863c37aeb5876fd12feda6a26299af928385dfc24e336f50f7ce9c692a4950c2da449937c5c771ce0bc3869cd1c442cc21b9916973e6e3fbfddb999f1d0
8155
+ checksum: 940119197dd0f9d35db8d59eb871171f857c4507363e50c2a7e9a430dfbf1055fd3bc43969eb5d2863d01b8dd86ae093371bf64cbead343065a7643769455738
8156
8156
languageName: node
8157
8157
linkType: hard
8158
8158
@@ -45849,7 +45849,7 @@ __metadata:
45849
45849
"@nestjs/passport": "npm:^9.0.3"
45850
45850
"@nestjs/platform-express": "npm:^9.0.0"
45851
45851
"@nestjs/schematics": "npm:^9.0.0"
45852
- "@nestjs/serve-static": "npm:^3 .0.0 "
45852
+ "@nestjs/serve-static": "npm:^4 .0.1 "
45853
45853
"@nestjs/terminus": "npm:^9.2.2"
45854
45854
"@nestjs/testing": "npm:^9.0.0"
45855
45855
"@nestjs/typeorm": "npm:^10.0.0"
You can’t perform that action at this time.
0 commit comments