-
Hi @alexhultman Is there any way like If there no method, any way realize this? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 20 comments 1 reply
-
res.redirect is an express thing In any case, if you want to redirect without express https://stackoverflow.com/questions/17898183/node-js-301-redirect-non-www-without-express Check the second answer. |
Beta Was this translation helpful? Give feedback.
-
Solved. Answer here |
Beta Was this translation helpful? Give feedback.
-
Reopen because didn't solved as getting absolute |
Beta Was this translation helpful? Give feedback.
-
You're trying to redirect the frontend right? just do
|
Beta Was this translation helpful? Give feedback.
-
@elieobeid7 No, only backend. I know how-to redirect front |
Beta Was this translation helpful? Give feedback.
-
You could use this |
Beta Was this translation helpful? Give feedback.
-
I can redirect to any url, except for backend, i want get url of |
Beta Was this translation helpful? Give feedback.
-
Why don't you use express if you think express would solve the issue? It's okay to just use it for redirect, or maybe ask on stackoverflow. I'm not sure the issue here but I'm not sure, I'm new here. What I would do is install express if I'm sure that express solves the problem. You see this library is an alternative to socket.io, in socket.io you can't do redirects, in websockets you can't do that either, so I don't think this library can do that, but the owner knows more than I do, so you could wait for his reply about what this library can and cannot do. |
Beta Was this translation helpful? Give feedback.
-
This library does more than Socket.io does and @alexhultman made the fastest web-server for Node.js ever have (fix me if i'm wrong). |
Beta Was this translation helpful? Give feedback.
-
Ah kudos! hopefully alex would help you more than I can :) |
Beta Was this translation helpful? Give feedback.
-
I hope too, thank you for help @elieobeid7 :) |
Beta Was this translation helpful? Give feedback.
-
btw in the example i showed the guy redirects to an absolute url, not sure why it's isn't working with you
|
Beta Was this translation helpful? Give feedback.
-
The problem comes when i'm trying to use |
Beta Was this translation helpful? Give feedback.
-
So you want something like so Alright until alex comes and fix it, here's a little hack, we know that the library runs on localhost + port What we could do is this
basically if
then you don't need /, but if it gives you |
Beta Was this translation helpful? Give feedback.
-
Thanks, little hack already i am did until i am found fix or author answers |
Beta Was this translation helpful? Give feedback.
-
From what I understand a redirect is just a response with that 300-ish status and a header with the URL. In that case you already have all the tools for this. |
Beta Was this translation helpful? Give feedback.
-
Thanks. If wontfix, it is not bad, not everyone uses this method. |
Beta Was this translation helpful? Give feedback.
-
In case anyone is struggling with redirects, the order of the calls matter. res
.writeHeader("Location", "https://example.com")
.writeStatus("302")
.end(); Will not work but res
.writeStatus("302")
.writeHeader("Location", "https://example.com")
.end(); will. Not sure if that's intentional but it seems to be the case. |
Beta Was this translation helpful? Give feedback.
-
First writeHeader calls writeStatus if not already done, so order matters yes |
Beta Was this translation helpful? Give feedback.
-
I think this thread had been answered - it takes a few lines of string concatenation but you do certainly have all the tools. It could be added as a built-in feature if more people would report this but I think it is kind of a high level thing. |
Beta Was this translation helpful? Give feedback.
I think this thread had been answered - it takes a few lines of string concatenation but you do certainly have all the tools. It could be added as a built-in feature if more people would report this but I think it is kind of a high level thing.