Skip to content

Commit 1fcb082

Browse files
authored
try fix wrong content type for js file (#269)
1 parent 01fdd29 commit 1fcb082

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

apps/api/src/app.module.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Module } from '@nestjs/common';
22
import { ServeStaticModule } from '@nestjs/serve-static';
3-
import { join } from 'path';
3+
import { extname, join } from 'path';
44

55
import { AppController } from './app.controller';
66
import { AppService } from './app.service';
@@ -18,10 +18,25 @@ import { TestSlotModule } from './test-slot/test-slot.module';
1818

1919
@Module({
2020
imports: [
21-
ServeStaticModule.forRoot({
22-
rootPath: join(__dirname, '..', '..', '..', 'web', 'dist'),
23-
exclude: ['/api/(.*)'],
24-
}),
21+
ServeStaticModule.forRoot(
22+
{
23+
rootPath: join(__dirname, '..', '..', '..', 'web', 'dist', 'assets'),
24+
serveRoot: '/assets', // available at https://yourdomain.com/assets/...
25+
exclude: ['/api/(.*)'], // API routes skip this
26+
serveStaticOptions: {
27+
setHeaders: (res, path) => {
28+
const ext = extname(path);
29+
if (ext === '.js') {
30+
res.setHeader('Content-Type', 'application/javascript');
31+
}
32+
},
33+
},
34+
},
35+
{
36+
rootPath: join(__dirname, '..', '..', '..', 'web', 'dist'),
37+
exclude: ['/api/(.*)', '/assets/(.*)'], // don’t override API or assets
38+
},
39+
),
2540
LoggerModule,
2641
InternModule,
2742
EmailModule,

0 commit comments

Comments
 (0)