node.js - Angular cli 代理配置不适用于本地主机?
问题描述
试图调用http://localhost:9001
使用角度代理配置运行的nodejs localhost但是我无法调用端点,知道我在下面的代码中实现了什么错误吗?
服务.ts
import { Injectable } from '@angular/core';
import { HttpClient , HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({ providedIn: 'root' })
export class AdminService {
constructor(private http: HttpClient) {}
private url = "/api/saveClients";
saveClientJobs(data) {
let options = this.createRequestOptions();
console.log("Service", data);
return this.http.post(this.url, data, {
headers: options
});
}
private createRequestOptions() {
let headers = new HttpHeaders({
"Content-Type": "application/json"
});
return headers;
}
}
proxy.config.json
{
"/api/*": {
"target": "http://localhost:9001",
"secure": false,
"logLevel": "debug"
}
}
包.json
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.config.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}
解决方案
推荐阅读
- php - 如何强制服务器使用 POST 而不是 GET
- python-3.x - 将值从瞬态模型传递给 One2many - odoo 13(错误值错误)
- reactjs - 使用 react redux 重置多个状态
- wordpress - 目录未加载任何内容(LuckyWP)
- java - 无法将 java 代码集成到我的 react native 项目中 - 错误:不兼容的类型:ReactApplicationContext 无法转换为 Activity
- ios - 应用内购买成功后关闭按钮 - Ios - Swift - Xcode
- angularjs - 为 angularJS URL 返回 401 的最简单方法
- amazon-cloudformation - 如何获取 AWS KMS Key Arn 并通过 CloudFormation 在 IAM 角色内联策略中传递它?
- c++ - 模板参数替换失败且未完成隐式转换
- python - Python:根据输入()从列表中删除一个项目?