Skip to content

Getting access to the request body to proxy to a development backend #115

Description

@jmzagorski

Thanks for the great work on the 11ty ecosystem! I would like to incorporate this plugin and remove @11ty/eleventy-server-browsersync, but I have a use case similar to #9. Below I show my use case with the browsersync plugin and http-proxy-middleware to proxy the entire request to a development backend. I believe this library could replicate the behavior below if onRequest passed the request or request body so that I could forward the request with the form data for methods such as POST (11ty creates HTML forms that post data)

What are your thoughts on this for your library?

    const apiProxy = createProxyMiddleware({
        pathFilter: opts.intercept,
        target: opts.backend,
        changeOrigin: true,
        logger: console,
        on: {
            proxyReq: function (proxyReq, req) {
                proxyReq.setHeader("Authorization", opts.authorization || "");
                proxyReq.setHeader(
                    "Referer",
                    req.headers.referer?.replace(
                        "http://localhost:8080",
                        `http://${process.env.HOSTNAME}:8080`,
                    ) || "",
                );
            },
        },
    });

    config.setServerOptions({
        module: "@11ty/eleventy-server-browsersync",
        port: 8080,
        open: false,
        notify: false,
        ui: false,
        ghostMode: false,
        snippet: true,
        middleware: [apiProxy],
    });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions