mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-09-09 11:15:08 +08:00
split api into multiple files
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { boolean } from "boolean";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
const handler = async (req, res) => {
|
||||
const token = await getToken({ req });
|
||||
|
||||
// Return nothing if the user isn't registered.
|
||||
if (!token) {
|
||||
res.status(401).end();
|
||||
return;
|
||||
}
|
||||
|
||||
const messagesRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/messages`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-API-Key": process.env.FASTAPI_KEY,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const messages = await messagesRes.json();
|
||||
|
||||
// Send recieved messages to the client.
|
||||
res.status(200).json(messages);
|
||||
};
|
||||
|
||||
export default handler;
|
||||
@@ -1,4 +1,3 @@
|
||||
import { boolean } from "boolean";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
const handler = async (req, res) => {
|
||||
@@ -11,9 +10,8 @@ const handler = async (req, res) => {
|
||||
}
|
||||
|
||||
//TODO: add params if needed
|
||||
const reqParams = req.query;
|
||||
const params = new URLSearchParams({
|
||||
username: boolean(reqParams.allUsers) ? "" : token.sub,
|
||||
username: token.sub,
|
||||
});
|
||||
|
||||
const messagesRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/messages?${params}`, {
|
||||
Reference in New Issue
Block a user