I am building a reverse proxy, in it, there is a form box. It is supposed to get user input, and check if it is:
- a url;
- a url without the https:// header, which it adds;
- or plain text, which is routed into a search engine.
Wen submitting the form, no matter what is in it, it returns “Cannot Post /” in a blank page. My index.html form is this.
<div class="search-container">
<p>Join the <a href="https://discord.gg/3TTahctF">discord</a>!</p>
<form id="fs" method="POST">
<input id="is" class="main-search" placeholder="A World, Uncensored" type="text" />
</form>
</div>
In my index.js, which is connected, this.
window.addEventListener('load', () => {
navigator.serviceWorker.register('../sw.js?v=4', {
scope: '/a/',
})
})
const form = document.getElementById('fs')
const input = document.getElementById('is')
if (form && input) {
form.addEventListener("submit", async event => {
event.preventDefault();
processUrl(input.value, "");
});
}
function processUrl(value, path) {
let url = value.trim()
const engine = localStorage.getItem('engine')
const searchUrl = engine ? engine : 'https://www.google.com/search?q='
if (!isUrl(url)) {
url = searchUrl + url
} else if (!(url.startsWith('https://') || url.startsWith('http://'))) {
url = 'https://' + url
}
sessionStorage.setItem('GoUrl', __uv$config.encodeUrl(url))
const dy = localStorage.getItem('dy')
if (path) {
location.href = path
} else if (dy === 'true') {
window.location.href = '/a/q/' + __uv$config.encodeUrl(url)
} else {
window.location.href = '/a/' + __uv$config.encodeUrl(url)
}
}
function isUrl(val = '') {
if (/^http(s?):///.test(val) || (val.includes('.') && val.substr(0, 1) !== ' ')) return true
return false
}
First, I tried changing the form’s method, which gave me a similar error. Then, after doing research online, I came to this link. Although similar, it is focused on an express error, while mine is basic javascript (client side).