This fixes the form submit URL when the request is not to the root path. Using the lastIndexOf "/" will get the last directory, but it always needs to be the root. So, for example, if the page being attempted is https://bouqs.com/flowers/all and the action is /flowers/all, the existing code would generate https://bouqs.com/flowers/flowers/all. The URL constructor can intelligently generate the URL from a given base: https://nodejs.org/api/url.html#url_constructor_new_url_input_base
This fixes the form submit URL when the request is not to the root path. Using the lastIndexOf "/" will get the last directory, but it always needs to be the root. So, for example, if the page being attempted is
https://bouqs.com/flowers/all
and the action is/flowers/all
, the existing code would generatehttps://bouqs.com/flowers/flowers/all
. The URL constructor can intelligently generate the URL from a given base: https://nodejs.org/api/url.html#url_constructor_new_url_input_base