Skip to content

Commit

Permalink
chore: Development - Communicate with backend through proxy by fronte…
Browse files Browse the repository at this point in the history
…nd (ng serve)

http://localhost:4200/ -> Frontend (Angular app)
http://localhost:4200/api -> Backend (NestJS app)
  • Loading branch information
mugifly committed Apr 13, 2022
1 parent 520fcde commit 701dce4
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 3 deletions.
7 changes: 7 additions & 0 deletions client/.proxy.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"/api": {
"target": "http://localhost:3000/",
"secure": false,
"logLevel": "debug"
}
}
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"start:dev": "ng serve --proxy-config .proxy.conf.json",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
Expand Down
289 changes: 286 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"name": "angular-nest",
"private": true,
"scripts": {
"start:dev": "concurrently --names ng,nest --kill-others \"npm run start:dev --workspace=client\" \"npm run start:dev --workspace=server\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"concurrently": "^7.1.0",
"prettier": "^2.3.2"
},
"workspaces": [
Expand Down
1 change: 1 addition & 0 deletions server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AppModule } from './app.module';

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

0 comments on commit 701dce4

Please sign in to comment.