(req, res)
| 624 | } |
| 625 | |
| 626 | async onRequestHandler (req, res) { |
| 627 | res = wrapResponse(res, content => { |
| 628 | |
| 629 | // check to see if this is a client fetch and not a navigation |
| 630 | let isXHR = req.headers["sec-fetch-mode"] && req.headers["sec-fetch-mode"] != "navigate"; |
| 631 | |
| 632 | if(this.options.liveReload !== false && !isXHR) { |
| 633 | let scriptContents = this.#getFileContents("./client/reload-client.js"); |
| 634 | let integrityHash = ssri.fromData(scriptContents); |
| 635 | |
| 636 | // Bare (not-custom) finalhandler error pages have a Content-Security-Policy `default-src 'none'` that |
| 637 | // prevents the client script from executing, so we override it |
| 638 | if(res.statusCode !== 200 && !res.isCustomErrorPage) { |
| 639 | res.setHeader("Content-Security-Policy", `script-src '${integrityHash}'`); |
| 640 | } |
| 641 | return this.augmentContentWithNotifier(content, res.statusCode !== 200, { |
| 642 | scriptContents, |
| 643 | integrityHash |
| 644 | }); |
| 645 | } |
| 646 | |
| 647 | return content; |
| 648 | }); |
| 649 | |
| 650 | let middlewares = this.options.middleware || []; |
| 651 | middlewares = middlewares.slice(); |
| 652 | |
| 653 | // TODO because this runs at the very end of the middleware chain, |
| 654 | // if we move the static stuff up in the order we could use middleware to modify |
| 655 | // the static content in middleware! |
| 656 | middlewares.push(this.eleventyProjectMiddleware); |
| 657 | middlewares.reverse(); |
| 658 | |
| 659 | // Runs very first in the middleware chain |
| 660 | middlewares.push(this.eleventyDevServerMiddleware); |
| 661 | |
| 662 | let bound = []; |
| 663 | let next; |
| 664 | |
| 665 | for(let ware of middlewares) { |
| 666 | let fn; |
| 667 | if(next) { |
| 668 | fn = ware.bind(this, req, res, next); |
| 669 | } else { |
| 670 | fn = ware.bind(this, req, res); |
| 671 | } |
| 672 | bound.push(fn); |
| 673 | next = fn; |
| 674 | } |
| 675 | |
| 676 | bound.reverse(); |
| 677 | |
| 678 | let [first] = bound; |
| 679 | await first(); |
| 680 | } |
| 681 | |
| 682 | getHosts() { |
| 683 | let hosts = new Set(); |
nothing calls this directly
no test coverage detected