2017-12-19 14 views
0

私はバックエンドのURL http://docker-users:5500/users?all=trueを持っています。私はユーザーのリストを返します。 angle-cliのlocalhostのURLはhttp://localhost:4200です。 proxy.config.jsonを設定してng serveに追加しました。問題は私が到達しようとしているときに私はまだ404エラーを取得しています。私のミスはどこにありますか?Angular-Cli CORSの設定

proxy.config.json:

{ 
    "/api/*": { 
    "target": "http://docker-users:5500", 
    "secure": false, 
    "changeOrigin": true 
    } 
} 

service.ts

const headers = new Headers({ 'Content-Type': 'application/json;'}); 
const params = new URLSearchParams(); 
params.append('all', true); 
const options = new RequestOptions({ headers: headers, params: params }); 
const resp = this.http.get('/api/users', options) 
... 

答えて

2

pathRewriteオプションを追加します。

{ 
    "/api": { 
    "target": "http://docker-users:5500", 
    "secure": false, 
    "pathRewrite": { 
     "^/api": "" 
    }, 
    "changeOrigin": true, 
    "logLevel": "debug" 
    } 
} 
+0

働いていません。多分URLを変更する必要があるかもしれません – TeodorKolev

+0

このコメントを削除することができます – TeodorKolev

+0

"http:// docker-users:5500/users?all = true"というURLは有効ですか? – anode7

関連する問題