thedevs-network / kutt

Free Modern URL Shortener.
https://kutt.it
MIT License
8.49k stars 1.11k forks source link

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

Open Nathan-Roberts123 opened 9 months ago

Nathan-Roberts123 commented 9 months ago

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.

https://github.com/thedevs-network/kutt/blob/041aed5ad6d9c049aaefa9f150e93bf8835f2203/server/utils/index.ts#L58-L62

To repro the error: 1.serve the project on http protocol, eg 'http://localhost:3000'

  1. create a shorted link, copy it and new browser tab and try to access it.
  2. It will show page not found, because it use https protocol
jaysnm commented 8 months ago

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.