Skip to content

Commit 97cf01a

Browse files
NestJS
1 parent 0e658e6 commit 97cf01a

File tree

8 files changed

+94
-0
lines changed

8 files changed

+94
-0
lines changed

client/app/app.component.css

Whitespace-only changes.

client/app/app.server.module.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NgModule } from '@angular/core';
2+
import { ServerModule } from '@angular/platform-server';
3+
4+
import { AppModule } from './app.module';
5+
import { AppComponent } from './app.component';
6+
7+
@NgModule({
8+
imports: [
9+
AppModule,
10+
ServerModule,
11+
],
12+
bootstrap: [AppComponent],
13+
})
14+
export class AppServerModule {}

client/main.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { AppServerModule } from './app/app.server.module';

client/tsconfig.server.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../dist-server/",
5+
"baseUrl": "./",
6+
"module": "commonjs",
7+
"types": []
8+
},
9+
"exclude": [
10+
"test.ts",
11+
"**/*.spec.ts"
12+
],
13+
"angularCompilerOptions": {
14+
"entryModule": "app/app.server.module#AppServerModule"
15+
}
16+
}

server/app.module.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Module } from '@nestjs/common';
2+
import { ApiModule } from './modules/api/api.module';
3+
4+
@Module({
5+
imports: [
6+
ApiModule
7+
],
8+
controllers: [],
9+
components: [],
10+
})
11+
export class ApplicationModule {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Controller, Get } from '@nestjs/common';
2+
3+
@Controller('api')
4+
export class ApiController {
5+
6+
@Get('hello')
7+
root(): string {
8+
return 'Hello World!';
9+
}
10+
}

server/modules/api/api.module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Module } from '@nestjs/common';
2+
import { ApiController } from './api.controller';
3+
4+
@Module({
5+
imports: [],
6+
controllers: [ApiController],
7+
components: [],
8+
})
9+
export class ApiModule {}

webpack.server.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
4+
module.exports = {
5+
entry: { server: './server/main.ts' },
6+
resolve: { extensions: ['.js', '.ts'] },
7+
target: 'node',
8+
// this makes sure we include node_modules and other 3rd party libraries
9+
externals: [/(node_modules|main\..*\.js)/],
10+
output: {
11+
path: path.join(__dirname, 'dist'),
12+
filename: '[name].js'
13+
},
14+
module: {
15+
rules: [
16+
{ test: /\.ts$/, loader: 'ts-loader' }
17+
]
18+
},
19+
plugins: [
20+
// Temporary Fix for issue: https://github.com/angular/angular/issues/11580
21+
// for "WARNING Critical dependency: the request of a dependency is an expression"
22+
new webpack.ContextReplacementPlugin(
23+
/(.+)?angular(\\|\/)core(.+)?/,
24+
path.join(__dirname, 'src'), // location of your src
25+
{} // a map of your routes
26+
),
27+
new webpack.ContextReplacementPlugin(
28+
/(.+)?express(\\|\/)(.+)?/,
29+
path.join(__dirname, 'src'),
30+
{}
31+
)
32+
]
33+
}

0 commit comments

Comments
 (0)