feat: whoami api

main
xtexChooser 2022-11-13 09:17:00 +08:00
parent 0f66983a07
commit c1505cfa61
No known key found for this signature in database
GPG Key ID: 978F2E760D9DB0EB
3 changed files with 41 additions and 17 deletions

View File

@ -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' })
}

27
pages/api/whoami.ts Normal file
View File

@ -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"],
})
}

View File

@ -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"
]
}