uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
8.08k stars 574 forks source link

App.domain docs #859

Closed MarcJo closed 1 year ago

MarcJo commented 1 year ago

This code works with v20.10.0 fails with v20.15.0 and v20.19.0 It's may be caused due to 'Improved SNI support' in uWebSockets v20.18.0 which does not look to be implemented.

const port = 443
SSLApp( {} )
.addServerName( 'page1.com', {
    key_file_name  : 'page1.com/key.pem',
    cert_file_name : 'page1.com/cert.pem',
} )
.addServerName( 'page2.com', {
    key_file_name  : 'page2.com/key.pem',
    cert_file_name : 'page2.com/cert.pem',
} )
.missingServerName( ( hostname ) => {

    console.log( 'Hello! We are missing server name <' + hostname + '>' )

} )
.get( '/*', ( res, req ) => {

    res.end( 'Hello World!' )

} )
.listen( port, ( token ) => {

    if ( token ) {

        console.log( 'Listening to port ' + port )

    } else {

        console.log( 'Failed to listen to port ' + port )

    }

} )
uNetworkingAB commented 1 year ago

Please read the release post. You attach routes to SNI domains using app.domain(..). You haven't specified any default SSL cert and you haven't attached any route to your "SNIs"

MarcJo commented 1 year ago

Thanks. Please provide type definition for app.domain(..).

This is working solution (checked with v20.19.0)

const port = 443
SSLApp( {} )
.addServerName( 'page1.com', {
    key_file_name  : 'page1.com/key.pem',
    cert_file_name : 'page1.com/cert.pem',
})
.domain('page1.com')    
.get( '/*', ( res, req ) => {

    res.end( 'Hello World! 1' )

} ) 
.addServerName( 'page2.com', {
    key_file_name  : 'page2.com/key.pem',
    cert_file_name : 'page2.com/cert.pem',
} )
.domain('page2.com')    
.get( '/*', ( res, req ) => {

    res.end( 'Hello World! 2' )

} ) 
.missingServerName( ( hostname ) => {

    console.log( 'Hello! We are missing server name <' + hostname + '>' )

} )
.listen( port, ( token ) => {

    if ( token ) {

        console.log( 'Listening to port ' + port )

    } else {

        console.log( 'Failed to listen to port ' + port )

    }

} )