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

[question] Creating a server with tls using Typescript #782

Closed
aleixdevelops opened this issue Oct 26, 2022 · 3 comments
Closed

[question] Creating a server with tls using Typescript #782

aleixdevelops opened this issue Oct 26, 2022 · 3 comments
Labels

Comments

@aleixdevelops
Copy link

I'm trying to update a project from mosca to aedes using typescript. When creating the server with the tsl module I'm getting:

"Argument of type '(stream: Connection, request: IncomingMessage) => Client' is not assignable to parameter of type '(socket: TLSSocket) => void'."

As mentioned in #487 it seems there is a type mismatch in the tsl module with the one in Aedes.d.ts. I've seen there are workarounds using a websocket server but I don't need it. Any idea how solve it? or what I'm getting wrong ?

import fs from 'node:fs';
import * as tls from 'node:tls';
import { Aedes } from 'aedes';

const aedes: Aedes = new Aedes();

const env = process.env.NODE_ENV || 'development';
const ascoltatoriConfig = domain.config.get('ascoltatori');

process.on('uncaughtException', function (err) {
  process.exit(1);
});

// TLS/SSL 

const SECURE_CERT =config.ssl_cert_path
const SECURE_KEY =config.ssl_key_path

const options = {
  key: fs.readFileSync(SECURE_KEY),
  cert: fs.readFileSync(SECURE_CERT)
}

const secureSettings = {
  port: 2883,
  secure: {
    port: 9883,
    keyPath: SECURE_KEY,
    certPath: SECURE_CERT
  },
  allowNonSecure: true,
  stats: false
};

domain.on('ready', function () {
  // global.server = new mosca.Server(secureSettings); //previous mosca implementation
  global.server = tls.createServer(options, aedes.handle) // Wasn't able to use aedes.handle as the secureConnectionListener param as the documentation mentions
})
@Gianluca-Casagrande-Stiga
Copy link
Contributor

Hi, let's try:

import aedes from 'aedes';

instead of

import { Aedes } from 'aedes';
const aedes: Aedes = new Aedes();

@aleixdevelops
Copy link
Author

@Gianluca-Casagrande-Stiga When I do a default import it doesn't let me import the methods from aedes, the only way I've find its been instantiating it

@robertsLando
Copy link
Member

tls.createServer(options, (socket) => {
	aedes.handle(socket)
})

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

3 participants