-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (45 loc) · 1.25 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
53
54
55
56
57
const fs = require('fs')
const path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const puppeteer = require('puppeteer')
const exportFunc = require('./export')
const {
PORT = 3000,
LIMIT = 1,
WIDTH = 1920,
HEIGHT = 1080
} = process.env
const exportpath = path.resolve(__dirname, 'public')
if (!fs.existsSync(exportpath)) fs.mkdirSync('public')
const server = express()
server.use(cors())
server.use(bodyParser.urlencoded({ extended: true, limit: `${LIMIT}mb` }))
server.use(bodyParser.json({ limit: `${LIMIT}mb` }))
server.use('/headless', express.static('headless'))
server.use('/', express.static('public'))
const boot = async function() {
const browser = await puppeteer.launch({
// headless: false,
// devtools: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
defaultViewport: {
width: WIDTH,
height: HEIGHT,
},
})
const browserWSEndpoint = browser.wsEndpoint()
server.post('/api/export', exportFunc({
PORT,
puppeteer,
browserWSEndpoint,
}))
server.get('/api/status', function (req, res) {
res.sendStatus(200)
})
server.listen(PORT, function () {
console.log('Server is listening', PORT)
})
}
boot()