Skip to content

Commit 701dce4

Browse files
committed
chore: Development - Communicate with backend through proxy by frontend (ng serve)
http://localhost:4200/ -> Frontend (Angular app) http://localhost:4200/api -> Backend (NestJS app)
1 parent 520fcde commit 701dce4

File tree

5 files changed

+297
-3
lines changed

5 files changed

+297
-3
lines changed

client/.proxy.conf.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"/api": {
3+
"target": "http://localhost:3000/",
4+
"secure": false,
5+
"logLevel": "debug"
6+
}
7+
}

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",
7+
"start:dev": "ng serve --proxy-config .proxy.conf.json",
78
"build": "ng build",
89
"watch": "ng build --watch --configuration development",
910
"test": "ng test"

package-lock.json

Lines changed: 286 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
"name": "angular-nest",
33
"private": true,
44
"scripts": {
5+
"start:dev": "concurrently --names ng,nest --kill-others \"npm run start:dev --workspace=client\" \"npm run start:dev --workspace=server\"",
56
"test": "echo \"Error: no test specified\" && exit 1"
67
},
78
"devDependencies": {
9+
"concurrently": "^7.1.0",
810
"prettier": "^2.3.2"
911
},
1012
"workspaces": [

server/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AppModule } from './app.module';
33

44
async function bootstrap() {
55
const app = await NestFactory.create(AppModule);
6+
app.setGlobalPrefix('api'); // Change the URL prefix to `/api` on backend
67
await app.listen(3000);
78
}
89
bootstrap();

0 commit comments

Comments
 (0)