File size: 1,065 Bytes
95af8b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { NextRequest, NextResponse } from "next/server";
import { auth, getIP } from "../../auth";

export async function POST(req: NextRequest) {
  try {
    const authResult = auth(req);
    if (authResult.error) {
      return NextResponse.json(authResult, {
        status: 401,
      });
    }
    const token=req.headers.get("auth") ?? ""
    let res=await fetch("https://eladmin.dwzynj.top/api/chatMessage/addChatMessage", {
        method: "POST",
        headers:{
          "Content-Type":'application/json;charset=utf-8',
          "Authorization":token,
          "UserIp": String(getIP(req))
        },
        body:JSON.stringify(await req.json())
      })
      if(res.status==401){
        let msg={
          flag:false,
          msg:"未登录!"
        }
      // console.log(res.status)
      return new Response(JSON.stringify(msg))
      }
    let msg=await res.json()
    // console.log(msg)
    return new Response(JSON.stringify(msg))
  } catch (e) {
    console.error("[eladmin] ", e);
    return new Response(JSON.stringify(e));
  }
}