【发布时间】:2021-01-13 03:00:32
【问题描述】:
我在 GitHub 上探索 MEAN Stack 项目,我才意识到他们 GitHub 上的 Angular 身份验证服务不使用任何基本 URL。例如,他们只是在 HttpClient.post 中使用 /api/auth/login 作为 URL。
由于没有 HttpInterceptor 来添加基本 URL,怎么可能?
【问题讨论】:
标签: angular mean-stack angular-httpclient
我在 GitHub 上探索 MEAN Stack 项目,我才意识到他们 GitHub 上的 Angular 身份验证服务不使用任何基本 URL。例如,他们只是在 HttpClient.post 中使用 /api/auth/login 作为 URL。
由于没有 HttpInterceptor 来添加基本 URL,怎么可能?
【问题讨论】:
标签: angular mean-stack angular-httpclient
默认情况下,Angular 会将其放在项目的 URL 之后。所以不是去/api/auth/login,而是去https://<projecturl>/api/auth/login,或者如果在本地主机http://localhost:4200/api/auth/login工作。
这里有一个 stackblitz 演示了这一点: https://stackblitz.com/edit/angular-ivy-cbtroa?file=src%2Fapp%2Fapp.component.ts
【讨论】: