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

Not getting Headers from Websocket implementation #46

Closed
mynlexi opened this issue May 23, 2023 · 2 comments
Closed

Not getting Headers from Websocket implementation #46

mynlexi opened this issue May 23, 2023 · 2 comments

Comments

@mynlexi
Copy link

mynlexi commented May 23, 2023

I would really like to switch from Baojs to Elysia, but i need the websocket headers to authenticate the messages

On Elysia i cant get them:
Elysia-log:

  "raw": ServerWebSocket {
    "binaryType": "uint8array",
    "close": [Function: close],
    "cork": [Function: cork],
    "data": {
      "request": Request (0 KB) {
        method: "GET",
        url: "http://localhost:3005/search/proxy_search_wsp/1"
      },
      "store": {},
      "set": {
        "headers": {},
        "status": 200
      },
      "publish": {
        "name": "publish"
      },
      "query": -1,
      "params": {
        "wsp": "1"
      },
      "id": 1684826648522,
      "message": undefined,
      "transformMessage": []
    },
    "getBufferedAmount": [Function: getBufferedAmount],
    "isSubscribed": [Function: isSubscribed],
    "publish": [Function: publish],
    "publishBinary": [Function: publishBinary],
    "publishText": [Function: publishText],
    "readyState": 1,
    "remoteAddress": "127.0.0.1",
    "send": [Function: send],
    "sendBinary": [Function: sendBinary],
    "sendText": [Function: sendText],
    "subscribe": [Function: subscribe],
    "unsubscribe": [Function: unsubscribe]
  },
  "data": {
    "request": Request (0 KB) {
      method: "GET",
      url: "http://localhost:3005/search/proxy_search_wsp/1"
    },
    "store": {},
    "set": {
      "headers": {},
      "status": 200
    },
    "publish": {
      "name": "publish"
    },
    "query": -1,
    "params": {
      "wsp": "1"
    },
    "id": 1684826648522,
    "message": undefined,
    "transformMessage": []
  },
  "isSubscribed": [Function: isSubscribed],
  "publish": [Function: publish],
  "publishToSelf": [Function: publishToSelf],
  "send": [Function: send],
  "subscribe": [Function: subscribe],
  "unsubscribe": [Function: unsubscribe],
  "cork": [Function: cork],
  "close": [Function: close]
} {
  "term": "tt"
}

Would appreciate help!

@SaltyAom
Copy link
Member

SaltyAom commented May 23, 2023

Should be fixed with 1d0c00a, update to Elysia 0.5.3 to see if this solve your problem.

To verify, this snippet should log a request's headers:

import { Elysia, ws } from 'elysia'

const app = new Elysia()
	.use(ws())
	.ws('/', {
		message(ws, message) {
			console.log(ws.data.headers)

			ws.send(message)
		}
	})
	.listen(3000)

@mynlexi
Copy link
Author

mynlexi commented May 24, 2023

Thank you worked perfectly!

@mynlexi mynlexi closed this as completed May 24, 2023
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