-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
45 lines (36 loc) · 1.27 KB
/
index.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const express = require('express')
const request = require('request')
const chalk = require('chalk')
const path = require('path')
const cors = require('cors')
const atob = require('atob')
const app = express()
app.use(cors())
app.get('/proxify', function (req, res) {
var url = atob(req.query.url)
if(url.match(/youtu\.?be(\.com)?|ytimg\.com|googlevideo\.com/)){
console.log(`${chalk.bgGreen(chalk.black(' ALLOW '))} ${chalk.green(url)}`)
req.pipe(request({
url: url,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
})).pipe(res)
} else{
console.log(`${chalk.bgRed(chalk.black(' DENY '))} ${chalk.red(url)} ${chalk.gray(JSON.stringify(req.query))}`)
res.status(403).send('Blacklisted URL')
}
})
if (app.get('env') === 'production') {
app.use(express.static('./dist'))
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, './dist', 'index.html'))
})
app.get('*.js', function (req, res, next) {
req.url = req.url + '.gz'
res.set('Content-Encoding', 'gzip')
res.set('Content-Type', 'text/javascript')
next()
})
}
app.listen(process.env.PORT || (app.get('env') === 'production' ? 8080 : 7000))