Skip to content

Rewrite request in middleware #13429

Answered by jezikk
jezikk asked this question in Q&A
Apr 18, 2025 · 3 comments · 4 replies
Discussion options

You must be logged in to vote

@vampcat Yeah You are right. This is working code:

import { paraglideMiddleware } from "~/paraglide/server";
import type { Route } from "../+types/root";

// https://github.com/opral/inlang-paraglide-js/issues/449
const localeMiddleware: Route.unstable_MiddlewareFunction = async (
  { request },
  next,
) => {
  const response = await paraglideMiddleware(request, () => {
    return next();
  });

  if (response.status === 307) {
    throw response;
  }

  return response;
};

export { localeMiddleware };

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@jezikk
Comment options

@vampcat
Comment options

@jezikk
Comment options

Answer selected by jezikk
Comment options

You must be logged in to vote
1 reply
@sergiodxa
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants