Fix type errors
This commit is contained in:
parent
d346ccf701
commit
98b1daa7d3
2 changed files with 11 additions and 12 deletions
|
|
@ -4,19 +4,21 @@ const ALLOWED_ACTIONS = ["start", "stop", "restart"];
|
||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
req: NextRequest,
|
req: NextRequest,
|
||||||
{ params }: { params: { service: string; action: string } },
|
{ params }: { params: Promise<{ service: string; action: string }> },
|
||||||
) {
|
) {
|
||||||
const token = req.cookies.get("token")?.value;
|
const token = req.cookies.get("token")?.value;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ALLOWED_ACTIONS.includes(params.action)) {
|
const { service, action } = await params;
|
||||||
|
|
||||||
|
if (!ALLOWED_ACTIONS.includes(action)) {
|
||||||
return NextResponse.json({ error: "Invalid action" }, { status: 400 });
|
return NextResponse.json({ error: "Invalid action" }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`http://localhost:3001/services/${params.service}/${params.action}`,
|
`http://localhost:3001/services/${service}/${action}`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,18 @@ import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
req: NextRequest,
|
req: NextRequest,
|
||||||
{ params }: { params: { service: string } },
|
{ params }: { params: Promise<{ service: string }> },
|
||||||
) {
|
) {
|
||||||
const token = req.cookies.get("token")?.value;
|
const token = req.cookies.get("token")?.value;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(
|
const { service } = await params;
|
||||||
`http://localhost:3001/services/${params.service}/logs`,
|
|
||||||
{
|
const res = await fetch(`http://localhost:3001/services/${service}/logs`, {
|
||||||
headers: {
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
Authorization: `Bearer ${token}`,
|
});
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return NextResponse.json(await res.json(), { status: res.status });
|
return NextResponse.json(await res.json(), { status: res.status });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue