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

Can not create a shortened link with HTTP protocol in development mode #735

Closed
Nathan-Roberts123 opened this issue Feb 2, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@Nathan-Roberts123
Copy link

Nathan-Roberts123 commented Feb 2, 2024

In development mode links get shortened to some thing like this 'https://localhost:3000/4MKUMy', this link has https protocol, but i am serving the project on 'http://localhost:3000', so when i try to open the shortened link i get an error 'ERR_SSL_PROTOCOL_ERROR'. So i have to manually change the shorted link to use http protocol, 'http://localhost:3000/4MKUMy' and then it will work.

This behavior happens even if CUSTOM_DOMAIN_USE_HTTPS=false is in the .env file

This happens because, in line 60 below, domain=undefined in development mode so !domain will be true so the https protocol will be used.

export const generateShortLink = (id: string, domain?: string): string => {
const protocol =
env.CUSTOM_DOMAIN_USE_HTTPS || !domain ? "https://" : "http://";
return `${protocol}${domain || env.DEFAULT_DOMAIN}/${id}`;
};

To repro the error:
1.serve the project on http protocol, eg 'http://localhost:3000'
2. create a shorted link, copy it and new browser tab and try to access it.
3. It will show page not found, because it use https protocol

jaysnm added a commit to jaysnm/kutt that referenced this issue Mar 21, 2024
@jaysnm
Copy link

jaysnm commented Mar 21, 2024

Hello @Nathan-Roberts123

I bumped into same issue a while ago and exactly as you have put it, the issue is on protocol definition on line 59 as you have shown above. To make decision of assigning http/https to the generated shortLink, I introduced a new environment variable DEFAULT_DOMAIN_HTTPS with a default of false. The default is likely to work for most environments including production where http traffic is redirected to https by webserver. Use the PR above if you need the feature.

In addition to your issue, I noticed mail templates are explicitly (hard-coded) using https for all routes (account verification, password change etc.). See .html files on server/mail directory. This is a quick fix as well as the logic can be defined on server/mail/mail.ts.

jaysnm added a commit to jaysnm/kutt that referenced this issue Mar 21, 2024
A fix for issue thedevs-network#735 to support http short links on development mode
@trgwii trgwii added the enhancement New feature or request label Feb 6, 2025
@trgwii
Copy link
Member

trgwii commented Feb 6, 2025

https://github.com/thedevs-network/kutt/blob/main/server/utils/utils.js#L76

This is the culprit in v3... @poeti8 did you know that you can do protocol-agnostic links with <a href="//host/path">...</a> ? That would make the links work 100% of the time when clicked...

@poeti8
Copy link
Contributor

poeti8 commented Feb 7, 2025

This is actually updated and should be fixed in v3, so that line you sent should work well. I guess I close the issue.

@poeti8 did you know that you can do protocol-agnostic links

Yes, but users usually want to copy the links not to click them, so sharing //example.com is not very helpful. This is also sent in the API response as well.

@poeti8 poeti8 closed this as completed Feb 7, 2025
@trgwii
Copy link
Member

trgwii commented Feb 7, 2025

You can do frontend JS to find the current protocol and host, and only use the paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants