next-edge-function-loader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = middlewareLoader;
  6. var _getModuleBuildInfo = require("./get-module-build-info");
  7. var _stringifyRequest = require("../stringify-request");
  8. function middlewareLoader() {
  9. const { absolutePagePath , page , rootDir } = this.getOptions();
  10. const stringifiedPagePath = (0, _stringifyRequest).stringifyRequest(this, absolutePagePath);
  11. const buildInfo = (0, _getModuleBuildInfo).getModuleBuildInfo(this._module);
  12. buildInfo.nextEdgeApiFunction = {
  13. page: page || "/"
  14. };
  15. buildInfo.rootDir = rootDir;
  16. return `
  17. import { adapter, enhanceGlobals } from 'next/dist/server/web/adapter'
  18. enhanceGlobals()
  19. var mod = require(${stringifiedPagePath})
  20. var handler = mod.middleware || mod.default;
  21. if (typeof handler !== 'function') {
  22. throw new Error('The Edge Function "pages${page}" must export a \`default\` function');
  23. }
  24. export default function (opts) {
  25. return adapter({
  26. ...opts,
  27. page: ${JSON.stringify(page)},
  28. handler,
  29. })
  30. }
  31. `;
  32. }
  33. //# sourceMappingURL=next-edge-function-loader.js.map