chore(): apply locale middleware to all store routes (#14305)
* chore(): apply locale middleware to all store routes * Create pink-papayas-brush.md
This commit is contained in:
committed by
GitHub
parent
8964a03fa1
commit
7b4dda5a17
6
.changeset/pink-papayas-brush.md
Normal file
6
.changeset/pink-papayas-brush.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"@medusajs/framework": patch
|
||||
---
|
||||
|
||||
chore(): apply locale middleware to all store routes
|
||||
@@ -25,6 +25,7 @@ export async function applyLocale(
|
||||
const queryLocale = req.query.locale as string | undefined
|
||||
if (queryLocale) {
|
||||
req.locale = normalizeLocale(queryLocale)
|
||||
delete req.query.locale
|
||||
return next()
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import { Logger, MedusaContainer } from "@medusajs/types"
|
||||
import { join } from "path"
|
||||
import { configManager } from "../config"
|
||||
import { MiddlewareFileLoader } from "./middleware-file-loader"
|
||||
import { authenticate, AuthType } from "./middlewares"
|
||||
import { applyLocale, authenticate, AuthType } from "./middlewares"
|
||||
import { createBodyParserMiddlewaresStack } from "./middlewares/bodyparser"
|
||||
import { ensurePublishableApiKeyMiddleware } from "./middlewares/ensure-publishable-api-key"
|
||||
import { errorHandler } from "./middlewares/error-handler"
|
||||
@@ -406,6 +406,18 @@ export class ApiLoader {
|
||||
this.#app.use(namespace, middleware as RequestHandler)
|
||||
}
|
||||
|
||||
#applyLocaleMiddleware(namespace: string) {
|
||||
this.#logger.debug(
|
||||
`Registering locale middleware for namespace ${namespace}`
|
||||
)
|
||||
let middleware = ApiLoader.traceMiddleware
|
||||
? ApiLoader.traceMiddleware(applyLocale, {
|
||||
route: namespace,
|
||||
})
|
||||
: applyLocale
|
||||
this.#app.use(namespace, middleware as RequestHandler)
|
||||
}
|
||||
|
||||
async load() {
|
||||
if (FeatureFlag.isFeatureEnabled("backend_hmr")) {
|
||||
;(global as any).__MEDUSA_HMR_API_LOADER__ = this
|
||||
@@ -482,6 +494,8 @@ export class ApiLoader {
|
||||
*/
|
||||
this.#applyStorePublishableKeyMiddleware("/store")
|
||||
|
||||
this.#applyLocaleMiddleware("/store")
|
||||
|
||||
this.#applyAuthMiddleware(
|
||||
routesFinder,
|
||||
"/store",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { validateAndTransformQuery } from "@medusajs/framework"
|
||||
import {
|
||||
applyDefaultFilters,
|
||||
applyLocale,
|
||||
applyParamsAsFilters,
|
||||
authenticate,
|
||||
clearFiltersByKey,
|
||||
@@ -64,10 +63,6 @@ async function applyMaybeLinkFilterIfNecessary(
|
||||
}
|
||||
|
||||
export const storeProductRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
matcher: "/store/products/*",
|
||||
middlewares: [applyLocale],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/store/products",
|
||||
|
||||
Reference in New Issue
Block a user