railwayapp-templates / soketi

Deploy Soketi on Railway. Simple, fast, and resilient open-source websockets server.
https://dev.new/t/soketi
4 stars 5 forks source link

Unable to make a connection with Pusher SDK #2

Closed ibrahimyaacob92 closed 10 months ago

ibrahimyaacob92 commented 1 year ago

I'm using this template to spin up Soketi Server and hook it up with NextJS application.

# /api/test.ts
import { type NextApiRequest, type NextApiResponse } from 'next';
import Pusher from 'pusher';

const pusher = new Pusher({
    appId: 'default',
    key: 'xxxx',
    secret: 'xxxx',
    useTLS: false,
    host: 'soketi-production-ab0f.up.railway.app',
    port: '6130',
});

const test = async (req: NextApiRequest, res: NextApiResponse) => {
    const data = await pusher.trigger('my-channel', 'my-event', {
        message: 'hello world',
    });

    console.log({ data });
    res.send('hello woprld');
};
export default test;

Error I'm getting image

I've tested the same code with my local soketi server and it works just fine. I'm suspecting something is not right with Railway.. again I'm not 100%. But I'm seeing a number of people also facing this issue but there's not documented solution out there.

Thank you

shininglove commented 1 year ago

Just wanted to +1 this, same exact issue. I think it would be better to just take this down. Even when going to the discord for Soketi, no one seems to be able to help.

Heljas commented 1 year ago

@ibrahimyaacob92 @shininglove Hi, I think I found a solution, check out my repo. You need to override a Railway port to 6001 and set the host to 0.0.0.0

shininglove commented 1 year ago

@Heljas I'll try this right away! What port did you use on the client to connect to this? 6001 or 443?

Heljas commented 1 year ago

@shininglove 6001

shininglove commented 1 year ago

@Heljas Not sure why I'm not able to connect still, I'll keep trying different methods, do you have snippets of your client and server code you used to connect?

Heljas commented 1 year ago

@shininglove Sure, server:

export const pusher = new Pusher({
  secret: process.env.SOKETI_APP_SECRET ?? "",
  appId: process.env.SOKETI_APP_ID ?? "",
  key: process.env.NEXT_PUBLIC_SOKETI_APP_KEY ?? "",
  host: process.env.NEXT_PUBLIC_SOKETI_APP_HOST ?? "", //xyz.up.railway.app
  cluster: "",
  useTLS: true
});
const client = new PusherJS(process.env.NEXT_PUBLIC_SOKETI_APP_KEY ?? "", {
  wsHost: process.env.NEXT_PUBLIC_SOKETI_APP_HOST,  //xyz.up.railway.app
  wsPort: parseInt(process.env.NEXT_PUBLIC_SOKETI_APP_PORT ?? ""), //6001
  cluster: "",
  disableStats: true,
  enabledTransports: ["ws", "wss"],
  channelAuthorization: {
    endpoint: "/api/realtime/authorize",
    transport: "ajax"
  }
});
Heljas commented 1 year ago

@shininglove Did you override PORT env on Railway? Could you send the error?

shininglove commented 1 year ago

@shininglove Did you override PORT env on Railway? Could you send the error?

YOU'RE AWESOME, YOU'RE RIGHT! That was the solution, the problem I was getting into was launching from the template. But I noticed in your repo looked different from the template. I cloned your repo, then manually deployed and overrode the port, and it finally worked!

Thank you so much! I'll share this with other people that were having these same issues.

Heljas commented 1 year ago

I'm glad it helped!

rennokki commented 1 year ago

Even so, just be careful that the template deploys the 0.x version of Soketi, which is not up-to-date. I created https://github.com/railwayapp-templates/soketi/pull/1, but it was closed.

Heljas commented 1 year ago

Sure, that's why I recommend a template from my repo, I also updated Dockerfile to use the latest Soketi version (1.5).

isaachinman commented 10 months ago

So yeah, this template is certainly out of date. cc @Milo123459 @brody192

Another question – has anyone been able to expose the 9601 port as well as the 6001 port on Railway, to consume usage/metrics info?

brody192 commented 10 months ago

OP was initialising the client wrong, TLS is required and the port would be 443.

isaachinman commented 10 months ago

Strange to see unfriendly behaviour from the maintainers of a paid-for PaaS...

The template is at the very least out of date in that it references a previous major version of Soketi. In upgrading, you will release that many env vars for Soketi have changed.

brody192 commented 10 months ago

I'm sorry but neither me or milo maintain any part of railway the platform, nor have we had any involvement in this template.

this template is also not maintained by railway but by a community member.

isaachinman commented 10 months ago

Oh, I see. Strange that they have community members maintaining repos on their official GH org.

Here's an up-to-date, working Dockerfile:

FROM quay.io/soketi/soketi:1.5.0-16-debian

ARG SOKETI_DEFAULT_APP_ID
ENV SOKETI_DEFAULT_APP_ID=$SOKETI_DEFAULT_APP_ID

ARG SOKETI_DEFAULT_APP_KEY
ENV SOKETI_DEFAULT_APP_KEY=$SOKETI_DEFAULT_APP_KEY

ARG SOKETI_DEFAULT_APP_SECRET
ENV SOKETI_DEFAULT_APP_SECRET=$SOKETI_DEFAULT_APP_SECRET

ENV SOKETI_HOST=0.0.0.0
brody192 commented 10 months ago

Strange that they have community members maintaining repos on their official GH org.

The repos I maintain on this org are repos I have created, usually for a template bounty.

Update: I have now been given ownership of the Soketi template and I will be given push permissions on this repo tomorrow. The Template itself has been updated and currently deploys from a forked (and updated) version of this repo, once I have push permissions on this rep it will be updated and the template will be updated to again deploy from this repo.

Update v2: The template now uses this updated repo, I am watching soketi's repo for releases and will do my best to update this repo accordingly

brody192 commented 10 months ago

Both the repo and template have been updated