Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload failing because of Websocker issues #5653

Open
2 tasks done
vedran-korponajic opened this issue Feb 19, 2025 · 1 comment
Open
2 tasks done

Upload failing because of Websocker issues #5653

vedran-korponajic opened this issue Feb 19, 2025 · 1 comment
Labels

Comments

@vedran-korponajic
Copy link

Initial checklist

  • I understand this is a bug report and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Link to runnable example

https://barevalue.com/uppy

Steps to reproduce

I have set up a simple Node.JS server for companion. When uploading from local, the upload works without issue, but the Websockets always fail.

I have searched the docs and tried everything but to no avail, so it seems there is a bug here, as the code is correct.

const express = require('express');
const companion = require('@uppy/companion');
const { json, urlencoded } = require('body-parser');
const session = require('express-session');
const cors = require('cors');
require('dotenv').config();

const app = express();
app.set('trust proxy', 1);

// CORS configuration for website.com
app.use(cors({
    origin: ['https://website.com', 'https://www.website.com'],
    credentials: true
}));

// Secure session configuration
app.use(session({
    secret: process.env.SESSION_SECRET,
    resave: false,
    saveUninitialized: false,
    cookie: {
        secure: true,
        httpOnly: true,
        domain: '.website.com',
        sameSite: 'none'
    }
}));

// Basic middleware
app.use(json());
app.use(urlencoded({ extended: true }));

app.use(function(req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE', 'FETCH');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
    res.setHeader('Access-Control-Allow-Credentials', true);
    next();
});

// Companion options
const companionOptions = {
    server: {
        host: 'uppy.website.com',
        protocol: 'https',
        path: ''
    },
	companionUrl: 'https://uppy.website.com',
    secret: process.env.COMPANION_SECRET,
    debug: true,
	filePath: 'temp',
	uploadUrls: true,
	providerOptions: {
  s3: {
    key: process.env.AWS_ACCESS_KEY_ID,
        secret: process.env.AWS_SECRET_ACCESS_KEY,
        bucket: 'website-files',
		Bucket: 'website-files',
        region: process.env.AWS_REGION,
	  acl: 'private',
  },
		dropbox: {
        key: process.env.DROPBOX_KEY,
        secret: process.env.DROPBOX_SECRET,
        // redirectUri: 'https://uppy.website.com/companion/oauth/callback'
    },
		 drive: {
    key: process.env.GOOGLE_KEY,         // OAuth Client ID
    secret: process.env.GOOGLE_SECRET,   // OAuth Client Secret
	redirectUri: 'https://uppy.website.com/drive/callback',		 
    // Optionally specify the scopes you need:
    // scope: ['https://www.googleapis.com/auth/drive.readonly'],
     //redirectUri: 'https://uppy.website.com/connect/google/callback'
  },
},

    corsOrigins: [
        'https://website.com',
        'https://www.website.com',
        /^https:\/\/.*\.website\.com$/
    ],

    redisUrl: process.env.REDIS_URL,
    metrics: false,
    // sendSelfEndpoint: 'https://uppy.website.com/companion'
};

const http = require('http');
const server = http.createServer(app);

// Attach Companion's WebSocket support to the HTTP server
companion.socket(server, companionOptions);
// Initialize companion
const companionApp = companion.app(companionOptions);

// Mount companion
app.use('/', companionApp);
app.use('/api', companionApp);

// Health check endpoint
app.get('/health', (req, res) => {
    res.json({ status: 'healthy', name: process.env.AWS_S3_BUCKET });
});

// Error handling
app.use((err, req, res, next) => {
    console.error('Server error:', err);
	const errorDetails = {
  		name: err.name,
  		message: err.message,
  		stack: err.stack
	};
	res.status(500).json(errorDetails);
    // res.status(500).json({ error: 'Internal server error', err: err });
});

const port = process.env.PORT || 3000;


server.listen(port, () => {
    console.log(`Companion server running on port ${port}`);
});

The server seems right, but I've been getting those errors for upload with download link and also with GoogleDrive uploads. If you try to upload anything with the link provided, you won't be able to do it.

Expected behavior

The upload should work for Google Drive and Direct download link.

Actual behavior

When working with Google Drive or a Download link it always fails with the following error:
RequestClient.js:386 WebSocket connection to 'wss://uppy.website.com/api/22059dc6-b67e-4a10-9b75-7df5df9c6c2d' failed: (anonymous) @ RequestClient.js:386 reconnectWebsocket @ RequestClient.js:385 (anonymous) @ index.js:56 (anonymous) @ retry_operation.js:116 (anonymous) @ index.js:54 pRetry @ index.js:31 (anonymous) @ RequestClient.js:449 (anonymous) @ RateLimitedQueue.js:148 _call2 @ RateLimitedQueue.js:231 run @ RateLimitedQueue.js:113 (anonymous) @ RateLimitedQueue.js:144 (anonymous) @ RateLimitedQueue.js:143 createWebsocket @ RequestClient.js:457 (anonymous) @ RequestClient.js:520 _awaitRemoteFileUpload2 @ RequestClient.js:336 (anonymous) @ RequestClient.js:296Understand this errorAI loggers.js:30 [Uppy] [14:07:57] Companion socket error {"isTrusted":true}, closing socket

@Murderlon
Copy link
Member

Maybe it helps to look at the standalone version to see what we do different:
https://github.com/transloadit/uppy/blob/main/packages/@uppy/companion/src/standalone/index.js

Or if you don't add anything besides Companion, you can just use the standalone version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants