You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
700 B
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import url from 'url';
export default async function (req, res) {
// 设置响应状态码和内容类型
res.writeHead(200, { 'Content-Type': 'application/json' });
// 获取请求的 Cookies这个只有相同域名才行没有意义
const cookies = req.headers.cookie;
// 解析 URL 和查询参数
const parsedUrl = url.parse(req.url, true);
const queryParams = parsedUrl.query;
// 返回 JSON 数据
const responseData = {
message: '我已经获取到该用户的cookie了',
cookies,
queryParams,
timestamp: new Date().toString(),
};
// 将数据写入响应体
res.end(JSON.stringify(responseData));
}