Skip to content

Passing return value of a function to target errors out #430

@Napster158

Description

@Napster158

Instead of a hardcoded string, when I pass a variable to the target option. It errors out.

My below function works, when the target is a harcoded url

const proxyMiddleware = proxy({
target: 'example.com',
changeOrigin: true,
pathRewrite: rewritePath,
});

When I pass a value returned by a function to target, it fails, errors out.

const artifactoryHost = function (req, res) {
const artifactoryHost = req.artifactoryHost;
return artifactoryHost;
};

const proxyMiddleware = proxy({
target: 'artifactoryHost',
changeOrigin: true,
pathRewrite: rewritePath,
});

I further went ahead and tried the router option, as below:

const proxyMiddleware = proxy({
target: 'https://ubit-artifactory.com',
router: artifactoryHost,
changeOrigin: true,
pathRewrite: rewritePath,
});

But then I started seeing weird errors in my console:

Unhandled rejection TypeError: Cannot read property 'split' of null

Any help, appreciated!! Is there a workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions