-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (43 loc) · 1.1 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
46
47
48
49
50
51
52
require('now-env')
const router = require('router')
const server = require('connect')()
const bodyParser = require('body-parser')
const scrape = require('scrape-fb-ogcache')
const serverRouter = router()
server.use(bodyParser.json({type: 'application/*'}))
const landing = require('./landing.js')
const privacy = require('./privacy.js')
const { PORT } = process.env
serverRouter.get('/privacy', (req, res) => {
res.write(privacy)
res.end()
})
serverRouter.post('/api/fetch', (req, res) => {
const url = req.body.url
res.writeHead(200, {
'Content-Type': 'application/json'
})
scrape(url, process.env.FBTOKEN, function (response) {
if (response.error) {
res.write(JSON.stringify({
error: true,
msg: response.error.error_user_msg
}))
res.end()
} else {
res.write(JSON.stringify({
error: false,
data: url
}))
res.end()
}
})
})
serverRouter.get('*', (req, res) => {
res.write(landing)
res.end()
})
server.use(serverRouter)
server.listen(PORT || 5001, () => {
console.log(`internet baby running on ${PORT || 5001}`)
})