feat: whoami api
parent
0f66983a07
commit
c1505cfa61
|
@ -1,13 +0,0 @@
|
|||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
type Data = {
|
||||
name: string
|
||||
}
|
||||
|
||||
export default function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import type { IncomingHttpHeaders } from 'node:http'
|
||||
|
||||
type Data = {
|
||||
httpVersion: string,
|
||||
headers: IncomingHttpHeaders,
|
||||
address: string,
|
||||
port: number,
|
||||
ipv6: boolean,
|
||||
method: string,
|
||||
userAgent: string | undefined,
|
||||
}
|
||||
|
||||
export default function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
res.status(200).json({
|
||||
httpVersion: req.httpVersion,
|
||||
headers: req.headers,
|
||||
address: req.socket.remoteAddress!,
|
||||
port: req.socket.remotePort!,
|
||||
ipv6: req.socket.remoteFamily == 'IPv6',
|
||||
method: req.method!,
|
||||
userAgent: req.headers["user-agent"],
|
||||
})
|
||||
}
|
|
@ -1,7 +1,11 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
|
@ -15,6 +19,12 @@
|
|||
"jsx": "preserve",
|
||||
"incremental": true
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
Reference in New Issue