Dear Andrew,
Thank’s a lot for your help.
I’ve tried to change the port, but the error is the same.
It seems I have diffuculties with Tus and Uppy Companion.
Could you please explain how to use Tus and Companion together on the server side? I’m not familiar with Node JS.
Because now I’m trying to combine it with my Django app written in Python.
What I have:
- for Tus I use Python library pypi.org/project/tus/ And it works OK for file uploads (Tus + Uppy). The Tus endpoint is http:// my_server_ip /files (port 80)
- I’ve installed and configured Node.JS and created the companion file companion.js. Please see the full code of companion file below. It’s listening the port 3020.
- In my Apache2 configuration I have
ProxyPass /companion http://localhost:3020
so I simply redirect all companion requests from http:// my_server_ip /companion to the companion server running under NodeJS (http:// localhost:3020).
and I see it works for url fetching. Companion can get details about urls that should be downloaded. And the endpoint http:// my_server_ip /companion works. But when I try to download files uppy checks the url http:// my_server_ip /companion/companion/url/get and failed (it doesn’t exists).
What I don’t understand:
- What is ‘/companion/url/get’ route? I don’t see the implementation of this in companion example. It
only has:
app.get(’/’, (req, res) => {
res.setHeader(‘Content-Type’, ‘text/plain’)
res.send(‘Welcome to Companion’)
})
and of course when my app checks ‘/companion/url/get’ it doesn’t exist. It returns
// handle 404
app.use((req, res, next) => {
return res.status(404).json({ message: ‘Not Found’ })
})
- How to run Tus and Companion both on NodeJS backend? Where I can find full example or tutorial? Maybe if I delete Tus implementation on Python and run all things (Tus, Companion) on NodeJS it will work.
Here is the full code of companion.js
const express = require(‘express’)
const companion = require(’…/…/node_modules/@uppy/companion’)
const bodyParser = require(‘body-parser’)
const session = require(‘express-session’)
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 || ‘*’)
res.setHeader(
‘Access-Control-Allow-Methods’,
‘GET, POST, OPTIONS, PUT, PATCH, DELETE’
)
res.setHeader(
‘Access-Control-Allow-Headers’,
‘Authorization, Origin, Content-Type, Accept’
)
next()
})
// Routes
app.get(’/’, (req, res) => {
res.setHeader(‘Content-Type’, ‘text/plain’)
res.send(‘Welcome to Companion’)
})
// initialize uppy
const uppyOptions = {
providerOptions: {
drive: {
key: ‘your google key’,
secret: ‘your google secret’
},
instagram: {
key: ‘your instagram key’,
secret: ‘your instagram secret’
}
},
server: {
host: ‘localhost:3020’,
protocol: ‘http’
},
filePath: ‘/var/www/uploads/’,
secret: ‘some-secret’,
debug: true
}
app.use(companion.app(uppyOptions))
// handle 404
app.use((req, res, next) => {
return res.status(404).json({ message: ‘Not Found’ })
})
// handle server errors
app.use((err, req, res, next) => {
console.error(’\x1b[31m’, err.stack, ‘\x1b[0m’)
res.status(err.status || 500).json({ message: err.message, error: err })
})
companion.socket(app.listen(3020), uppyOptions)
console.log(‘Welcome to Companion!’)
console.log(Listening on 3020
)