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

Support : Where to include sslOptions when initializing SOCKET #25

Open
sanyam810 opened this issue Mar 13, 2024 · 1 comment
Open

Support : Where to include sslOptions when initializing SOCKET #25

sanyam810 opened this issue Mar 13, 2024 · 1 comment

Comments

@sanyam810
Copy link

sanyam810 commented Mar 13, 2024

I'm currently working on a WebSocket server using next-ws in a Next.js environment. I need to include SSL options (Want to include ssl certificate & key) when initializing the WebSocket server , but I'm unsure how to do this properly.

import { NextRequest, NextResponse } from 'next/server';
import WebSocket from 'ws';

type DrawLine = {
    prevPoint: Point | null;
    currentPoint: Point;
    color: string;
    x: number;
    y: number;
};

const clients: Set<WebSocket> = new Set();

function SOCKET(
    client: WebSocket,
    request: import('http').IncomingMessage,
    server: WebSocketServer,
) {
    // WebSocket server logic
}

function GET(req: NextRequest, res: NextResponse) {
    // Handle GET request
}

function POST(req: NextRequest, res: NextResponse) {
    // Handle POST request
}

export { SOCKET, GET, POST };

I need guidance on how to properly include SSL because the connection to WS don't get established when in production environment

@apteryxxyz
Copy link
Owner

Using a custom server where you create your own WebSocketServer instance and tell Next WS to use that, you could pass additional options there.

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

No branches or pull requests

2 participants