-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathindex.js
73 lines (63 loc) · 1.6 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
const express = require('express')
const bodyParser = require('body-parser')
const session = require('express-session')
const companion = require('@uppy/companion')
const app = express()
app.use(bodyParser.json())
app.use(session({
secret: 'some-secret',
resave: true,
saveUninitialized: true,
}))
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*')
next()
})
// Routes
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'text/plain')
res.send('Welcome to Companion')
})
// initialize uppy
const companionOptions = {
providerOptions: {
drive: {
key: 'your google key',
secret: 'your google secret',
},
instagram: {
key: 'your instagram key',
secret: 'your instagram secret',
},
dropbox: {
key: 'your dropbox key',
secret: 'your dropbox secret',
},
box: {
key: 'your box key',
secret: 'your box secret',
},
// you can also add options for additional providers here
},
server: {
host: 'localhost:3020',
protocol: 'http',
},
filePath: './output',
secret: 'some-secret',
debug: true,
}
const { app: companionApp } = companion.app(companionOptions)
app.use(companionApp)
// handle 404
app.use((req, res) => {
return res.status(404).json({ message: 'Not Found' })
})
// handle server errors
app.use((err, req, res) => {
console.error('\x1b[31m', err.stack, '\x1b[0m')
res.status(500).json({ message: err.message, error: err })
})
companion.socket(app.listen(3020))
console.log('Welcome to Companion!')
console.log(`Listening on http://0.0.0.0:${3020}`)