add port config
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import http from 'http';
|
||||
import { handleRequest } from './module/index.ts';
|
||||
import { useConfig } from '@abearxiong/use-config';
|
||||
useConfig();
|
||||
const { port } = useConfig<{ port: number }>();
|
||||
const server = http.createServer((req, res) => {
|
||||
// res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
// const pathname = new URL(req.url, `http://${dns.hostName}`).pathname;
|
||||
@@ -9,7 +9,6 @@ const server = http.createServer((req, res) => {
|
||||
// res.write(`Request from ${dns.hostName} with IP: ${dns.ip}\n`);
|
||||
// res.end('Hello World\n');
|
||||
});
|
||||
|
||||
server.listen(3005, () => {
|
||||
console.log('Server running at http://localhost:3005/');
|
||||
server.listen(port, () => {
|
||||
console.log(`Server running at http://localhost:${port}/`);
|
||||
});
|
||||
|
||||
@@ -76,13 +76,19 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
||||
if (_api === 'api') {
|
||||
// 代理到 http://codeflow.xiongxiao.me/api
|
||||
// 设置代理请求的目标 URL 和请求头
|
||||
let header: any = {};
|
||||
if (req.headers?.['Authroization']) {
|
||||
header.Authorization = req.headers?.['Authroization'];
|
||||
}
|
||||
if (req.headers?.['Content-Type']) {
|
||||
header['Content-Type'] = req.headers?.['Content-Type'];
|
||||
}
|
||||
const options = {
|
||||
host: api.host,
|
||||
path: req.url,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': req.headers['content-type'],
|
||||
Authroization: req.headers?.['authorization'] || '',
|
||||
...header,
|
||||
},
|
||||
};
|
||||
// 创建代理请求
|
||||
|
||||
Reference in New Issue
Block a user