Karma: Allow regular expressions in proxies definition

Created on 25 Feb 2016  路  2Comments  路  Source: karma-runner/karma

Wished behavior

I would like to be able to tell Karma to serve a file whatever the sub-path is.
I could also want to transform the URL to something completely different.
For instance, something like this (but it won't work with the object syntax):

proxies: {
    /\/images\/.*/: "/base/test/assets/placeholder.png",
    /\/books/(\d+)\/pages\/(\d+)/: "http://external.host/get_book_page.php?book_id=$1&page_id=$2"
}

Proposed syntax

proxies could accept an object, as it is currently the case, or an array of arrays, which is still readable, and accepts regular expressions as "keys":

proxies: [
    [/\/images\/.*/, "/base/test/assets/placeholder.png"],
    [/\/books/(\d+)\/pages\/(\d+)/, "http://external.host/get_book_page.php?book_id=$1&page_id=$2"]
]
discuss help wanted feature

Most helpful comment

Support for regular expressions would be great.

Maybe Karma could support same confix syntax as Webpack does: https://github.com/webpack/webpack-dev-server/pull/127#issuecomment-89819809 (This change has been merged in https://github.com/webpack/webpack-dev-server/pull/187)

All 2 comments

Support for regular expressions would be great.

Maybe Karma could support same confix syntax as Webpack does: https://github.com/webpack/webpack-dev-server/pull/127#issuecomment-89819809 (This change has been merged in https://github.com/webpack/webpack-dev-server/pull/187)

Any plans on this ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jambonrose picture jambonrose  路  5Comments

ORESoftware picture ORESoftware  路  4Comments

kiramclean picture kiramclean  路  4Comments

macjohnny picture macjohnny  路  5Comments

simonh1000 picture simonh1000  路  3Comments