fix: restructure inbox API routes — channel/ and message/ namespaces

Next.js не позволяет [channelId] и [id] на одном уровне.
Решение: /api/inbox/channel/[channelId]/* и /api/inbox/message/[id]/*
InboxTab: все fetch пути обновлены
This commit is contained in:
Ник (Claude)
2026-06-11 20:14:40 +03:00
parent d262c2af7d
commit 59016a7490
6 changed files with 27 additions and 51 deletions
-27
View File
@@ -1,27 +0,0 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
const ENGINE_URL = process.env.ENGINE_URL || 'http://localhost:3030';
const ENGINE_SECRET = process.env.ENGINE_SECRET || '';
async function engineReq(path, opts = {}) {
const { method = 'GET', body, userId } = opts;
const headers = { 'x-internal-secret': ENGINE_SECRET };
if (userId) headers['x-user-id'] = String(userId);
if (body) headers['Content-Type'] = 'application/json';
const res = await fetch(`${ENGINE_URL}${path}`, {
method, headers, body: body ? JSON.stringify(body) : undefined,
});
return res.json();
}
export async function GET(req, { params }) {
const user = await requireUser();
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const { searchParams } = new URL(req.url);
const data = await engineReq(
`/api/inbox/${params.channelId}?${searchParams.toString()}`,
{ userId: user.id }
);
return NextResponse.json(data);
}
@@ -0,0 +1,16 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
const ENGINE_URL = process.env.ENGINE_URL || 'http://localhost:3030';
const ENGINE_SECRET = process.env.ENGINE_SECRET || '';
export async function GET(req, { params }) {
const user = await requireUser();
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const { searchParams } = new URL(req.url);
const res = await fetch(
`${ENGINE_URL}/api/inbox/${params.channelId}?${searchParams.toString()}`,
{ headers: { 'x-internal-secret': ENGINE_SECRET, 'x-user-id': String(user.id) } }
);
return NextResponse.json(await res.json());
}
@@ -4,23 +4,14 @@ import { requireUser } from '@/lib/session';
const ENGINE_URL = process.env.ENGINE_URL || 'http://localhost:3030';
const ENGINE_SECRET = process.env.ENGINE_SECRET || '';
async function enginePost(path, userId, body) {
const res = await fetch(`${ENGINE_URL}${path}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-internal-secret': ENGINE_SECRET,
'x-user-id': String(userId),
},
body: JSON.stringify(body),
});
return res.json();
}
export async function POST(req, { params }) {
const user = await requireUser();
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const body = await req.json().catch(() => ({}));
const data = await enginePost(`/api/inbox/${params.id}/reply`, user.id, body);
return NextResponse.json(data);
const res = await fetch(`${ENGINE_URL}/api/inbox/${params.id}/reply`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'x-internal-secret': ENGINE_SECRET, 'x-user-id': String(user.id) },
body: JSON.stringify(body),
});
return NextResponse.json(await res.json());
}
@@ -10,11 +10,7 @@ export async function POST(req, { params }) {
const body = await req.json().catch(() => ({}));
const res = await fetch(`${ENGINE_URL}/api/inbox/${params.id}/status`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-internal-secret': ENGINE_SECRET,
'x-user-id': String(user.id),
},
headers: { 'Content-Type': 'application/json', 'x-internal-secret': ENGINE_SECRET, 'x-user-id': String(user.id) },
body: JSON.stringify(body),
});
return NextResponse.json(await res.json());