+ 5

How to make http request to localhost express server from sololearn?

18th Aug 2021, 5:51 PM
Abhay
Abhay - avatar
25 Respostas
+ 3
sorry What does localhost do?
20th Aug 2021, 8:32 AM
Esthi
Esthi - avatar
+ 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
18th Aug 2021, 7:47 PM
Kiwwi#
Kiwwi# - avatar
+ 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
18th Aug 2021, 8:10 PM
Giorgos
+ 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
18th Aug 2021, 9:42 PM
Giorgos
+ 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
19th Aug 2021, 4:02 AM
Giorgos
+ 2
Kode Krasher Ngrok will make nonpublic localhost routable on the internet VIA SSH tunel.
20th Aug 2021, 7:01 AM
Jerzy Supryn
Jerzy Supryn - avatar
+ 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 .
20th Aug 2021, 11:14 AM
Hazel Audrin
Hazel Audrin - avatar
+ 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)
18th Aug 2021, 6:22 PM
Giorgos
+ 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 .
18th Aug 2021, 6:33 PM
Abhay
Abhay - avatar
+ 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
18th Aug 2021, 6:41 PM
Giorgos
+ 1
Giorgos D ok ty :) . I have allowed all origins but still it doesn't works .
18th Aug 2021, 6:53 PM
Abhay
Abhay - avatar
+ 1
Martin Taylor thanks a lot! Now i see why i can't make request from sololearn .
18th Aug 2021, 8:04 PM
Abhay
Abhay - avatar
+ 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.
18th Aug 2021, 8:15 PM
Abhay
Abhay - avatar
+ 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 ) !
18th Aug 2021, 10:16 PM
Abhay
Abhay - avatar
+ 1
The next question, do you know?
19th Aug 2021, 5:33 PM
German Loulou
+ 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.
19th Aug 2021, 5:40 PM
Abhay
Abhay - avatar
+ 1
You colud make SSH tunel to localhost by for example ngrok.com and make request to it.
20th Aug 2021, 5:29 AM
Jerzy Supryn
Jerzy Supryn - avatar
+ 1
Xbdnhdhddhdhh i have reported you for spamming .
20th Aug 2021, 3:24 PM
Abhay
Abhay - avatar
0
Kiwwi# ty as well.
18th Aug 2021, 8:05 PM
Abhay
Abhay - avatar
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 .
20th Aug 2021, 11:11 AM
Hazel Audrin
Hazel Audrin - avatar