BackendStack21 / restana

Restana is a lightweight and fast Node.js framework for building RESTful APIs.
MIT License
467 stars 27 forks source link

socket.io handshake error 403 when using http2 #63

Closed m-dary-nur closed 4 years ago

m-dary-nur commented 4 years ago

thank you for this leightweight framework, i had a problem when i use with restana with http2 when socket.io handshake , it say error during handshake: error 403

but with https its working perfectly. thank you for your answer before.

jkyberneees commented 4 years ago

Hi @m-dary-nur, thanks for reaching out.

To be honest, I haven't tested restana with HTTP2 and Socket.io. Still, having a 403 status code is pretty strange because it is not coming from restana itself. If you can share some minimal source code, I can help you to fix the issue...

Looking forward to hear from you.

m-dary-nur commented 4 years ago

this is my code in index.js

const http2 = require('http2')
const app = require('restana')({
        server: http2.createSecureServer({
            logger: true,
            ignoreTrailingSlash: true,
            cert: fs.readFileSync('./fullchain.pem'),
            key: fs.readFileSync('./privkey.pem')
        })
    })

app.start(13131).then(server => {
    if (server) {
        console.log('server running now')
    } else {
        console.log('failed to running server')
    }
})

const io = require('./io').io.listen(app.getServer())
io.set('origins', '*:*')

in io.js

const io = require('socket.io')()

io.on('connection', socket => {
    socket.on('user connected', param => {
        socket.emit('connected', param)
    })
})

exports.io = io

thank you for help me before

jkyberneees commented 4 years ago

Hi @m-dary-nur, as promised, I have spent some time on debugging the http2 issue. Unfortunately, I also failed on getting socket.io working properly with an http2 server. I can say this issue is not related to restana itself, but to how http2 servers interact with WebSocket connections, specially using socket.io.

I have added a demo using https, it works as expected as you mentioned. Thanks.

I am closing this issue here, please let me know if you succeed on this.

Best Regards, Rolando

m-dary-nur commented 4 years ago

Okay i'll update this issue if solved, thank you