+ 5
How to make http request to localhost express server from sololearn?
25 Respostas
+ 3
sorry What does localhost do?
+ 2
as addition to Martin Taylor answer, localhost is often used for run some tests when you are developing, simulating that you are connecting to the web, but its fake, you only are connecting with you own computer. Its for security majorly
+ 2
Complementing on Kiwwi# answer, localhost can also be used to built desktop apps in the form of local websites, using the usual html/css/js instead of Java for example
+ 2
Abhay Well i just tested this on playground from web and it works for me, you will need to run the express server first to work on you
https://code.sololearn.com/W5HitGmtE4ar/?ref=app
+ 2
Abhay Sorry for late reply, like real webpages on web code bits the webpage is run locally on your phone/pc, only the other languages (node, python, etc) are run on the sololearn server and yes they wouldnt be able to access your localhost.
edit: I tried on android with termux, it works as expected on browser but not in the sololearn android app. It must be because the local server runs with HTTP and not HTTPS, and the app blocks HTTP requests. You can verify by trying to fetch http://example.com So if you had https://localhost url it would probably work
+ 2
Kode Krasher Ngrok will make nonpublic localhost routable on the internet VIA SSH tunel.
+ 2
If the path starts with file: // and then the path of the file on the local disk, a local file is used. On the other hand, if you view one of the examples we host on GitHub (or another example on a remote server), the URL will start with http: // or https: // just like https://www.ghostwritingfounder.com/ to indicate that the file was received via HTTP .
+ 1
If your local server allowed CORS requests from different domains or just from sololearn.com then you could make requests to it and read the responses. But if another user ran the code bit he wouldnt have the local server running for it work.
You will have to publish your server somewhere (e.g. Heroku) and use that public web address.
Or use a secure tunnel to localhost (e.g. ngrok).
Or if you like to live dangerously, port forward your PC from your router and use your public IP instead (not recommended just saying)
+ 1
Giorgos D ty vm ! But why do i need to publish server on somewhere ? And when i try to make request to localhost from sololearn i get error "type error , failed to fetch". Do you have any idea why it is happening ? Again ty .
+ 1
Abhay Well i assumed you would want to publish your code bit and if so when another user ran it on his pc or phone his localhost wouldnt have your local server, he would only access it if it was public somewhere. As for the error idk, try configuring CORS to allow all origins in your local server, if still doesnt work idk
+ 1
Giorgos D ok ty :) . I have allowed all origins but still it doesn't works .
+ 1
Martin Taylor thanks a lot! Now i see why i can't make request from sololearn .
+ 1
Giorgos D sorry had to unmark your answer as best and ty for replying . I have never used java for local website but good to know . And i have never touched a desktop app . I use termux on android just.
+ 1
Giorgos D i can't excess sololearn web playground on android but good to know it's working from web .
And i would love to know how it is doing so if external network (like sololearn can't excess localhost ) !
+ 1
The next question, do you know?
+ 1
German Loulou what do you mean ? And you can't go on asking anything in comment section of other question . Please delete your comment as it doesn't answer my question at all.
+ 1
You colud make SSH tunel to localhost by for example ngrok.com and make request to it.
+ 1
Xbdnhdhddhdhh i have reported you for spamming .
0
Kiwwi# ty as well.
0
If the path starts with file: // and then the path of the file on the local disk, a local file is used. On the other hand, if you view one of the examples we host on GitHub (or another example on a remote server), the URL will start with http: // or https: // like https://www.ghostwritingfounder.com/ to indicate that the file was received via HTTP .