提交 e75bc305 编写于 作者: U u014071104

Wed Mar 13 09:51:00 CST 2024 inscode

上级 ca207a2f
run = "npm i && npm run dev" run = "npm i && npm run dev"
language = "node"
[env] [env]
PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}" PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}"
XDG_CONFIG_HOME = "/root/.config" XDG_CONFIG_HOME = "/root/.config"
npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global" npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global"
\ No newline at end of file
[debugger]
program = "main.js"
console.log("欢迎来到 InsCode"); const http = require('http');
\ No newline at end of file const https = require('https');
const url = require('url');
const PORT = 3000; // 你的代理服务器端口
const httpTool = (url, cb) => {
console.log("https?", url.startsWith("https"), url)
let ishttps = url.startsWith("https");
if (ishttps) {
return https.get(url, cb);
}
else {
return http.get(url, cb);
}
}
const server = http.createServer((req, res) => {
const parsedUrl = url.parse(req.url, true);
console.log("href", parsedUrl.query.url)
const targetPath = parsedUrl.query.url;
// 创建一个请求到原始图片服务器
const targetReq = httpTool(targetPath, (targetRes) => {
// 将原始服务器的响应转发给客户端
res.writeHead(targetRes.statusCode, targetRes.headers);
console.log("流数据接受中..")
targetRes.pipe(res);
});
targetReq.on('error', (err) => {
console.error(`请求 ${targetPath} 时出错:`, err);
res.writeHead(500);
res.end('图片代理服务器内部错误');
});
});
server.listen(PORT, () => {
console.log(`图片代理服务器正在运行,监听端口 ${PORT}`);
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册