@lolyjs/core 0.2.0-alpha.33 → 0.2.0-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -10409,7 +10409,7 @@ function matchApiRoute(routes, pathname) {
10409
10409
  if (!match) continue;
10410
10410
  const params = {};
10411
10411
  r.paramNames.forEach((name, idx) => {
10412
- params[name] = match[idx + 1];
10412
+ params[name] = decodeURIComponent(match[idx + 1] || "");
10413
10413
  });
10414
10414
  return { route: r, params };
10415
10415
  }
@@ -17107,6 +17107,7 @@ function getAutoRateLimiter(route, strictPatterns = [], rateLimitConfig) {
17107
17107
  // modules/server/handlers/api.ts
17108
17108
  async function handleApiRequest(options) {
17109
17109
  const { apiRoutes, urlPath, req, res, env = "dev", rewriteLoader } = options;
17110
+ const originalUrlPath = urlPath;
17110
17111
  let finalUrlPath = urlPath;
17111
17112
  let extractedParams = {};
17112
17113
  if (rewriteLoader) {
@@ -17145,6 +17146,33 @@ async function handleApiRequest(options) {
17145
17146
  }
17146
17147
  const sanitizedParams = sanitizeParams(params);
17147
17148
  const sanitizedQuery = sanitizeQuery(req.query);
17149
+ function reconstructPathFromParams(routePattern, params2) {
17150
+ let reconstructed = routePattern;
17151
+ for (const [key, value] of Object.entries(params2)) {
17152
+ const catchAllPattern = `[...${key}]`;
17153
+ if (reconstructed.includes(catchAllPattern)) {
17154
+ reconstructed = reconstructed.replace(catchAllPattern, value);
17155
+ } else {
17156
+ const normalPattern = `[${key}]`;
17157
+ if (reconstructed.includes(normalPattern)) {
17158
+ reconstructed = reconstructed.replace(normalPattern, value);
17159
+ }
17160
+ }
17161
+ }
17162
+ return reconstructed;
17163
+ }
17164
+ const reconstructedPath = reconstructPathFromParams(route.pattern, sanitizedParams);
17165
+ const queryString = req.url?.includes("?") ? req.url.split("?")[1] : "";
17166
+ const originalUrl = queryString ? `${reconstructedPath}?${queryString}` : reconstructedPath;
17167
+ if (!req.originalUrl) {
17168
+ req.originalUrl = originalUrl;
17169
+ }
17170
+ if (!req.params) {
17171
+ req.params = {};
17172
+ }
17173
+ for (const [key, value] of Object.entries(sanitizedParams)) {
17174
+ req.params[key] = value;
17175
+ }
17148
17176
  const ctx = {
17149
17177
  req,
17150
17178
  res,