mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-06 13:14:33 -06:00
Add GET-only (for now) config fetching API route
This commit is contained in:
35
src/pages/api/config.ts
Normal file
35
src/pages/api/config.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type {NextApiRequest, NextApiResponse} from 'next';
|
||||
import {env} from '@/env/server.mjs';
|
||||
import {fetchConfiguration} from "@/db";
|
||||
import {Configuration} from "@/timing";
|
||||
|
||||
type StatusData = { status: ResponseStatus };
|
||||
|
||||
type ResponseStatus =
|
||||
| 'unauthorized'
|
||||
| 'failed'
|
||||
| 'success';
|
||||
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<StatusData | Configuration>
|
||||
) {
|
||||
if (req.query.key != env.API_KEY) {
|
||||
// auth failed
|
||||
res.status(401).json({status: 'unauthorized'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method == "GET") {
|
||||
try {
|
||||
const configuration = await fetchConfiguration();
|
||||
res.status(200).json(configuration);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({status: "failed"});
|
||||
}
|
||||
} else if (req.method == "POST") {
|
||||
res.status(200).json({status: 'success'});
|
||||
}
|
||||
}
|
||||
15
yarn.lock
15
yarn.lock
@@ -186,6 +186,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.36.tgz#c414052cb9d43fab67d679d5f3c641be911f5835"
|
||||
integrity sha512-FXKWbsJ6a1hIrRxv+FoukuHnGTgEzKYGi7kilfMae96AL9UNkPFNWJEEYWzdRI9ooIkbr4AKldyuSTLql06vLQ==
|
||||
|
||||
"@types/prismjs@^1.26.0":
|
||||
version "1.26.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.26.0.tgz#a1c3809b0ad61c62cac6d4e0c56d610c910b7654"
|
||||
integrity sha512-ZTaqn/qSqUuAq1YwvOFQfVW1AR/oQJlLSZVustdjwI+GZ8kr0MSHBj0tsXPW1EqHubx50gtBEjbPGsdZwQwCjQ==
|
||||
|
||||
"@types/prop-types@*":
|
||||
version "15.7.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
|
||||
@@ -778,6 +783,11 @@ prettier@^2.8.4:
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"
|
||||
integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==
|
||||
|
||||
prismjs@^1.29.0:
|
||||
version "1.29.0"
|
||||
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12"
|
||||
integrity sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==
|
||||
|
||||
querystring@^0.2.0:
|
||||
version "0.2.1"
|
||||
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd"
|
||||
@@ -806,6 +816,11 @@ react-hook-form@^7.43.2:
|
||||
resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-7.43.2.tgz#d8ff71956dc3de258dce19d4b1c7e1c6a0188e67"
|
||||
integrity sha512-NvD3Oe2Y9hhqo2R4I4iJigDzSLpdMnzUpNMxlnzTbdiT7NT3BW0GxWCzEtwPudZMUPbZhNcSy1EcGAygyhDORg==
|
||||
|
||||
react-simple-code-editor@^0.13.1:
|
||||
version "0.13.1"
|
||||
resolved "https://registry.yarnpkg.com/react-simple-code-editor/-/react-simple-code-editor-0.13.1.tgz#4514553fa132dcaffec33a6612c58f1613c52416"
|
||||
integrity sha512-XYeVwRZwgyKtjNIYcAEgg2FaQcCZwhbarnkJIV20U2wkCU9q/CPFBo8nRXrK4GXUz3AvbqZFsZRrpUTkqqEYyQ==
|
||||
|
||||
react@18.2.0:
|
||||
version "18.2.0"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
|
||||
|
||||
Reference in New Issue
Block a user