11ty / 11ty/dev-server

Allow `onRequest` callbacks to access build-time file content

Open
#30 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs-votes
Dominant language
JavaScript
Stars
109
Forks
20
Avg merge
1m
Merged PRs (30d)
1

Description

Related to #29.

This is what works now:

const { EleventyServerlessBundlerPlugin } = require("@11ty/eleventy");

module.exports = function(eleventyConfig) {
  eleventyConfig.setServerOptions({
    middleware: [function overrideMiddleware(req, res, next) {
      // This works now
      res.writeHead(200, {"content-type": "text/html"}); // content-type header required for live-reload
      res.write("Before Text");
      res.end();

      next();
    }],
  });
});

However, I’d like to see folks able to consume res.statusCode (404 when no file is present) and res.body with the static content to do request-time content transforms

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 tracing how onRequest callbacks and the middleware shown in the issue receive the request and response. Check the behavior for an existing file and a missing file, then verify that callbacks can read static content through res.body and distinguish missing files through res.statusCode (404).

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.