-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
3 changed files
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './error'; | ||
export * from './manifest'; | ||
export * from './market'; | ||
export * from './request'; | ||
export * from './types'; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const LOBE_PLUGIN_SETTINGS = 'X-LOBE_PLUGIN_SETTINGS'; | ||
|
||
export const getPluginSettingsStringFromRequest = <T = any>(req: Request): T | undefined => { | ||
const settings = req.headers.get(LOBE_PLUGIN_SETTINGS); | ||
if (!settings) return; | ||
|
||
try { | ||
return JSON.parse(settings); | ||
} catch { | ||
return settings as any; | ||
} | ||
}; | ||
|
||
export const createHeadersWithPluginSettings = ( | ||
settings: any, | ||
header?: HeadersInit, | ||
Check failure on line 16 in src/request.ts GitHub Actions / Test
|
||
): HeadersInit => { | ||
Check failure on line 17 in src/request.ts GitHub Actions / Test
|
||
return { | ||
...header, | ||
[LOBE_PLUGIN_SETTINGS]: typeof settings === 'string' ? settings : JSON.stringify(settings), | ||
}; | ||
}; |