Skip to content

q123q cn 代码

sh
const express = require('express')
const fs = require("fs");
const https = require('https');

const app = express()
const port = 9000

app.get('*', (req, res) => {

  if(req.originalUrl.startsWith('/form'))return forward2ggfw_rlsbj(req,res)

  const data = fs.readFileSync("./index.html");
  res.set("Content-Type", "text/html; charset=utf-8");
  res.set("Qins-Tag","2025");
  if (data) {
    res.send(data);
  } else {
    res.send(`<h2>读取index.html失败</h2>`);
  }
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

function forward2ggfw_rlsbj(req,res){

  const headers = {
    Host: 'ggfw.rlsbj.q123q.cc',
    'User-Agent': req.headers['user-agent'],
    Accept: req.headers['accept'],
    'Accept-Language': req.headers['accept-language'],
  };

  if (req.headers['content-type']) headers['Content-Type'] = req.headers['content-type'];
  if (req.headers['content-length']) headers['Content-Length'] = req.headers['content-length'];
  if (req.headers['authorization']) headers['Authorization'] = req.headers['authorization'];
  if (req.headers['cookie']) headers['Cookie'] = req.headers['cookie'];

  const options = {
    hostname: 'ggfw.rlsbj.q123q.cc',
    port: 443,
    path: req.originalUrl,
    method: req.method,
    headers,
    rejectUnauthorized: false, // 如果是自签证书则必加
  };

  const proxyReq = https.request(options, (proxyRes) => {
    res.writeHead(proxyRes.statusCode, proxyRes.headers);
    proxyRes.pipe(res); // 将目标响应流直接传回客户端
  });

  proxyReq.on('error', (err) => {
    console.error('请求失败:', err.message);
    res.status(500).send('请求目标服务器失败:\n\n'+JSON.stringify(options)+'\n\n'+err.message);
  });

  proxyReq.end(); // 发起请求

}