forked from netptop/siteproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
24 lines (21 loc) · 1.06 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const fs = require('fs')
const path = require('path')
const ProxyMiddleware = require('http-proxy-middleware')
var Proxy = require('../Proxy')
let { blockedSites, urlModify, httpprefix, serverName, port, locationReplaceMap302, regReplaceMap, siteSpecificReplace, pathReplace } = require('../config')
let cookieDomainRewrite = serverName
let proxy = Proxy({ ProxyMiddleware, blockedSites, urlModify, httpprefix, serverName, port, cookieDomainRewrite, locationReplaceMap302, regReplaceMap, siteSpecificReplace, pathReplace })
export default (req, res) => {
const dirPath = path.join(__dirname + '/..', req.url)
console.log(`x-forward-for:${req.headers['x-forwarded-for']}, req.url:${req.url}`)
if (req.url === '/' || req.url === '/index.html') {
let body = fs.readFileSync(path.join(__dirname, '../index.html'), 'utf-8')
res.status(200).send(body)
return
} else
if (fs.existsSync(dirPath) && !fs.lstatSync(dirPath).isDirectory()) {
let body = fs.readFileSync(dirPath)
return res.status(200).send(body)
}
proxy(req, res, null) // next: null
}