Khaled Ayed
Khaled Ayed

Reputation: 1277

config proxy in angular cli

I want to use proxy config in angular-cli

this is my file:

{
    "/api/server": {
        "target": "http://other-site/server",
        "secure": false,
        "logLevel": "debug",
        "pathRewrite": { "^/api/server": "" },
        "changeOrigin": true
    },
    "/api/group": {
        "target": "http://other-site/group",
        "secure": false,
        "logLevel": "debug",
        "pathRewrite": { "^/api/group": "" },
        "changeOrigin": true
    },
    "/api/group/activate": {
        "target": "http://other-site/group/activate",
        "secure": false,
        "logLevel": "debug",
        "pathRewrite": { "^/api/group/activate": "" },
        "changeOrigin": true
    } 
}

it works for me , but i need a other effective solution ( juste remove pattern /api and concatinate with target , for example;

 change "/api/server" to "http://other-site/server" ...etc

i am trying with the code below, but doesn't work

{
    "/api": {
        "target": "http://other-site/",
        "secure": false,
        "logLevel": "debug",
        "pathRewrite": {"^/api" : ""},
        "changeOrigin": true
    },
}

Upvotes: 2

Views: 273

Answers (1)

Ghoul Ahmed
Ghoul Ahmed

Reputation: 4806

use pattern "/api/*" ,Try with this:

{
    "/api/*": {
        "target": "http://other-site",
        "secure": false,
        "logLevel": "debug",
        "pathRewrite": { "^/api": "" },
        "changeOrigin": true
    }
}

Upvotes: 2

Related Questions