mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-27 17:00:54 +01:00
* feat: add object base64 hash method * chore: add script to add package * feat: add request-handler package * wip: add request handlers for all jobs and widget api procedures * wip: remove errors shown in logs, add missing decryption for secrets in cached-request-job-handler * wip: highly improve request handler, add request handlers for calendar, media-server, indexer-manager and more, add support for multiple inputs from job handler creator * refactor: move media-server requests to request-handler, add invalidation logic for dns-hole and media requests * refactor: remove unused integration item middleware * feat: add invalidation to switch entity action of smart-home * fix: lint issues * chore: use integration-kind-by-category instead of union for request-handlers * fix: build not working for tasks and websocket * refactor: add more logs * refactor: readd timestamp logic for diconnect status * fix: lint and typecheck issue * chore: address pull request feedback
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import type { NextRequest } from "next/server";
|
|
import { createTRPCClient, httpLink } from "@trpc/client";
|
|
import SuperJSON from "superjson";
|
|
|
|
import type { AppRouter } from "@homarr/api";
|
|
import { createHeadersCallbackForSource } from "@homarr/api/client";
|
|
import { createI18nMiddleware } from "@homarr/translation/middleware";
|
|
|
|
export async function middleware(request: NextRequest) {
|
|
// fetch api does not work because window is not defined and we need to construct the url from the headers
|
|
// In next 15 we will be able to use node apis and such the db directly
|
|
const culture = await serverFetchApi.serverSettings.getCulture.query();
|
|
|
|
// We don't want to fallback to accept-language header so we clear it
|
|
request.headers.set("accept-language", "");
|
|
const next = createI18nMiddleware(culture.defaultLocale);
|
|
return next(request);
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/((?!api|static|.*\\..*|_next|favicon.ico|robots.txt).*)"],
|
|
};
|
|
|
|
export const serverFetchApi = createTRPCClient<AppRouter>({
|
|
links: [
|
|
httpLink({
|
|
url: `http://${process.env.HOSTNAME ?? "localhost"}:3000/api/trpc`,
|
|
transformer: SuperJSON,
|
|
headers: createHeadersCallbackForSource("server-fetch"),
|
|
}),
|
|
],
|
|
});
|