mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-09 02:06:39 -06:00
Allow returning raw configuration from fetchConfiguration
This commit is contained in:
@@ -6,14 +6,18 @@ import { format } from 'date-fns';
|
|||||||
const redis = new Redis(env.REDIS_URL, { maxRetriesPerRequest: 2 });
|
const redis = new Redis(env.REDIS_URL, { maxRetriesPerRequest: 2 });
|
||||||
|
|
||||||
export async function fetchConfiguration(
|
export async function fetchConfiguration(
|
||||||
defaultConfig?: object
|
defaultConfig?: object,
|
||||||
|
getParsed = true
|
||||||
): Promise<Configuration> {
|
): Promise<Configuration> {
|
||||||
const config = await redis.get('config');
|
const config = await redis.get('config');
|
||||||
if (config == null)
|
if (config == null)
|
||||||
if (defaultConfig != undefined)
|
if (defaultConfig != undefined)
|
||||||
return ConfigurationSchema.parse(defaultConfig);
|
return ConfigurationSchema.parse(defaultConfig);
|
||||||
else throw new Error('Configuration not found in Redis');
|
else throw new Error('Configuration not found in Redis');
|
||||||
return ConfigurationSchema.parse(JSON.parse(config));
|
|
||||||
|
const json = JSON.parse(config);
|
||||||
|
const parsed = ConfigurationSchema.parse(json);
|
||||||
|
return getParsed ? parsed : json;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getKey(identifier: string, now: Date) {
|
export function getKey(identifier: string, now: Date) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ const LoginPage: NextPage = () => {
|
|||||||
router.push({pathname: "/", query: {"key": data.token}}).then();
|
router.push({pathname: "/", query: {"key": data.token}}).then();
|
||||||
} else
|
} else
|
||||||
setError(true);
|
setError(true);
|
||||||
console.log(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div className="flex bg-zinc-900 min-h-screen h-full flex-col justify-center py-12 sm:px-6 lg:px-8">
|
return <div className="flex bg-zinc-900 min-h-screen h-full flex-col justify-center py-12 sm:px-6 lg:px-8">
|
||||||
|
|||||||
Reference in New Issue
Block a user