11ty / 11ty/dev-server

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

Open
#115 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

duplicate
Dominant language
JavaScript
Stars
109
Forks
20
Avg merge
1m
Merged PRs (30d)
1

Description

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 https://github.com/11ty/eleventy-dev-server/issues/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],
    });

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the server's onRequest hook and the http-proxy-middleware example included in the issue. Determine how request data is currently exposed and define completion as enabling a development-backend proxy to forward form data for methods such as POST.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.