Angular 代理 - proxy.conf.json 中的意外标记
Angular proxy - Unexpected token in proxy.conf.json
我有一个有效的 Angular 6 设置来制作 HttpRequests,但我需要通过代理 运行 它们。
所以我在 package.json:
旁边创建了一个 proxy.conf.json
{
"/loans/": {
"target" : "https://api.zonky.cz",
"secure" : false,
"changeOrigin" : true
}
}
并像这样更新了我的 package.json:
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
在 运行ning npm start 我得到:
C:\Users\Tom\Javascript\testhttp\proxy.conf.json: Unexpected token � in JSON at position 0
SyntaxError: C:\Users\Tom\Javascript\testhttp\proxy.conf.json: Unexpected token � in JSON at position 0
at JSON.parse (<anonymous>)
at Object.Module._extensions..json (module.js:671:27)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at DevServerBuilder._addProxyConfig (C:\Users\Tom\Javascript\testhttp\node_modules\@angular-devkit\build-angular\src\dev-server\index.js:244:27)
at DevServerBuilder._buildServerConfig (C:\Users\Tom\Javascript\testhttp\node_modules\@angular-devkit\build-angular\src\dev-server\index.js:177:18)
at Observable.rxjs_1.Observable.obs [as _subscribe] (C:\Users\Tom\Javascript\testhttp\node_modules\@angular-devkit\build-angular\src\dev-server\index.js:42:47)
at Observable._trySubscribe (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\Observable.js:43:25)
at Observable.subscribe (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\Observable.js:29:22)
at C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\util\subscribeTo.js:22:31
at Object.subscribeToResult (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\util\subscribeToResult.js:7:45)
at MergeMapSubscriber._innerSub (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\operators\mergeMap.js:75:38)
at MergeMapSubscriber._tryNext (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\operators\mergeMap.js:72:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! testhttp@0.0.0 start: `ng serve --proxy-config proxy.conf.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the testhttp@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Tom\AppData\Roaming\npm-cache\_logs18-06-17T13_52_55_968Z-debug.log
版本:
Angular CLI: 6.0.8
Node: 8.11.2
OS: win32 x64
Angular: 6.0.5
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cli 6.0.8
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.1
typescript 2.7.2
webpack 4.8.3
有人知道我该如何解决这个问题吗? JSON 验证者说我的 proxy.conf.json 是有效的 JSON.
编辑
我在 powershell 中创建了 proxy.conf.json 文件,如下所示:
echo >> proxy.conf.json
这显然弄乱了文件 - 当我从 windows 界面再次创建文件时它起作用了。
尝试创建新文件并复制到新文件:
{
"\/api": {
"target": "https://api.zonky.cz",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite": {
"^\/api": "/"
}
}
}
我有一个有效的 Angular 6 设置来制作 HttpRequests,但我需要通过代理 运行 它们。 所以我在 package.json:
旁边创建了一个 proxy.conf.json{
"/loans/": {
"target" : "https://api.zonky.cz",
"secure" : false,
"changeOrigin" : true
}
}
并像这样更新了我的 package.json:
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
在 运行ning npm start 我得到:
C:\Users\Tom\Javascript\testhttp\proxy.conf.json: Unexpected token � in JSON at position 0
SyntaxError: C:\Users\Tom\Javascript\testhttp\proxy.conf.json: Unexpected token � in JSON at position 0
at JSON.parse (<anonymous>)
at Object.Module._extensions..json (module.js:671:27)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at DevServerBuilder._addProxyConfig (C:\Users\Tom\Javascript\testhttp\node_modules\@angular-devkit\build-angular\src\dev-server\index.js:244:27)
at DevServerBuilder._buildServerConfig (C:\Users\Tom\Javascript\testhttp\node_modules\@angular-devkit\build-angular\src\dev-server\index.js:177:18)
at Observable.rxjs_1.Observable.obs [as _subscribe] (C:\Users\Tom\Javascript\testhttp\node_modules\@angular-devkit\build-angular\src\dev-server\index.js:42:47)
at Observable._trySubscribe (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\Observable.js:43:25)
at Observable.subscribe (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\Observable.js:29:22)
at C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\util\subscribeTo.js:22:31
at Object.subscribeToResult (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\util\subscribeToResult.js:7:45)
at MergeMapSubscriber._innerSub (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\operators\mergeMap.js:75:38)
at MergeMapSubscriber._tryNext (C:\Users\Tom\Javascript\testhttp\node_modules\rxjs\internal\operators\mergeMap.js:72:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! testhttp@0.0.0 start: `ng serve --proxy-config proxy.conf.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the testhttp@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Tom\AppData\Roaming\npm-cache\_logs18-06-17T13_52_55_968Z-debug.log
版本:
Angular CLI: 6.0.8
Node: 8.11.2
OS: win32 x64
Angular: 6.0.5
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cli 6.0.8
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.1
typescript 2.7.2
webpack 4.8.3
有人知道我该如何解决这个问题吗? JSON 验证者说我的 proxy.conf.json 是有效的 JSON.
编辑
我在 powershell 中创建了 proxy.conf.json 文件,如下所示:
echo >> proxy.conf.json
这显然弄乱了文件 - 当我从 windows 界面再次创建文件时它起作用了。
尝试创建新文件并复制到新文件:
{
"\/api": {
"target": "https://api.zonky.cz",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite": {
"^\/api": "/"
}
}
}