-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (62 loc) · 2.21 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const express = require('express')
const superagent = require('superagent')
const cookieParser = require('cookie-parser')
// const redis = require('redis')
const { createWorker, createScheduler } = require('tesseract.js')
const app = express()
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(express.json({ limit: '50mb' }))
app.use(express.urlencoded({ limit: '50mb', extended: true, parameterLimit: 50000 }))
// setup queue
// const bullQueue = new Queue('', {
// redis: {
// port: 15957,
// host: process.env.REDISURL,
// password: process.env.REDISPASSWORD
// }
// })
// app.set('bullQueue', bullQueue)
// const redisCache = redis.createClient({
// url: `redis://${process.env.REDISURL}`,
// password: process.env.REDISPASSWORD,
// tls: true
// })
// app.set('redisCache', redisCache)
// tesser queue
async function initTesseractQuee(app) {
// 2 works = ability to handle 2 jobs at once; no speed difference on 1 job
const scheduler = createScheduler()
const worker = createWorker()
await worker.load()
await worker.loadLanguage() // default english
await worker.initialize() // default english
scheduler.addWorker(worker)
const worker2 = createWorker()
await worker2.load()
await worker2.loadLanguage() // default english
await worker2.initialize() // default english
scheduler.addWorker(worker2)
app.set('tesseractScheduler', scheduler)
}
initTesseractQuee(app)
// setup universal useragent
superagent
.get('https://omahaproxy.appspot.com/win')
.end((err, res) => {
if (err) console.error(err)
app.set('useragent', `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${res.text.substring(0, res.text.indexOf('.'))}.0.0.0 Safari/537.36`)
})
// set up routes
app.use('/ocr', require('./routes/ocr'))
app.use('/get', require('./routes/get'))
app.use('/heartbeat', require('./routes/heartbeat'))
app.use('/sendgridreceive', require('./routes/sendgridreceive'))
var port = process.env.PORT
if (port == null || port === '') {
port = 8080
}
app.listen(port, () => {
console.log(`Listening at http://localhost:${port}`)
})