"use strict";

exports.__esModule = true;
exports.default = void 0;
const MatchPathLoader = async function () {
  const params = new URLSearchParams(this.resourceQuery);
  const matchPath = params.get(`matchPath`);
  const modulePath = this.resourcePath;
  return (/* javascript */`
  const preferDefault = m => (m && m.default) || m

  const functionToExecute = preferDefault(require('${modulePath}'));
  const matchPath = '${matchPath}';
  const { match: reachMatch } = require('@gatsbyjs/reach-router');

  module.exports = function(req, res) {
    let functionPath = req.originalUrl

    functionPath = functionPath.replace(new RegExp('^/*' + PREFIX_TO_STRIP), '')
    functionPath = functionPath.replace(new RegExp('^/*api/?'), '')

    const matchResult = reachMatch(matchPath, functionPath)
    if (matchResult) {
      req.params = matchResult.params
      if (req.params['*']) {
        // TODO(v6): Remove this backwards compatability for v3
        req.params['0'] = req.params['*']
      }
    }

    return functionToExecute(req, res);
  }
  `
  );
};
var _default = MatchPathLoader;
exports.default = _default;
//# sourceMappingURL=match-path-webpack-loader.js.map