-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
36 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
import { defineMiddleware } from "astro:middleware"; | ||
import { useConfigApi } from "./index.ts"; | ||
|
||
export const onRequest = defineMiddleware(async (context, next) => { | ||
context.locals.config = await useConfigApi().config({ | ||
let resolvedValue; | ||
|
||
async function getConfigPromise(context) { | ||
console.log("request config request"); | ||
if (resolvedValue) { | ||
// If the value is already resolved, return a resolved promise with the value | ||
return resolvedValue; | ||
} | ||
console.log("config request"); | ||
// Fetch the config and store the resolved value | ||
const value = await useConfigApi().config({ | ||
lang: context.currentLocale, | ||
}); | ||
resolvedValue = value; | ||
return value; | ||
} | ||
|
||
export const onRequest = defineMiddleware((context, next) => { | ||
context.locals.config = getConfigPromise(context); | ||
return next(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters