Help needed for Active learning: make it all async!

Hi,

I’m starting the assessment on this page. I’ve copied the starting source code and the coffee.jpg image locally and started a localhost plain vanilla node server on port 3000. When I attempt to run the starter code, my console produces this error: async-sync.html:12 Fetch API cannot load file:///Users/artletter1/MDN-JS-Tuts/coffee.jpg. URL scheme must be “http” or “https” for CORS request.

What do I have to do in order to proceed with the exercise?

Thanks!

Roy

Hello @royjay

it’s cause of the security of the fetch api it can not be called to access local file

there are a note on this page https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Introducing for that

Note: For security reasons, you can’t fetch() files from your local filesystem (or run other such operations locally); to run the above example locally you’ll have to run the example through a local webserver.

hope that help and have a nice day

@justsomeone

Thank you for your quick reply! I thought I took care of that requirement by running a local Node server in that folder, but obviously not! How do I proceed?

Thanks!

Roy

you welcome @royjay

from this file:///Users/artletter1/MDN-JS-Tuts/coffee.jpg. URL scheme must be “http” or “https” for CORS request.

it’s look like something not configured right in your webserver

check this link it has webserver for each platform https://www.maketecheasier.com/setup-local-web-server-all-platforms/

hope that help and have a nice day

I started a web server on my Mac with “sudo apachectl start”. When I navigate to localhost in my web browser I receive the “It works!” reply, so the webserver appears to be up and running. Yet I get the same error when attempting to run the MDN example.

Any other thoughts?

Roy

are you sure you put your html stuff inside the folder of the apache server ?

@royjay
and you do not run the html file by just simply click on it you need to navigat to it using the webserver

each webserver has default folder you put your files there then you open your browser then access it using the following line
localhost/the folder name of your prject / your html file
or use 127.0.0.1 instead of the localhost word

hope that help

@royjay @justsomeone we’ve also got some helpful tips here: https://wiki.developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server

In short, I’d recommend using Python HTTPSimpleServer, as I find it quick and easy to use.

But yes, you need to find out what URL the server is serving the content on, and navigate to that URL in your browser. It’ll look something like localhost:7000

thanks @chrisdavidmills :slight_smile:

@justsomeone, your last suggestion did the trick. Even though I had the web server up and running, I had navigated directly to the html file in my browser.

Thank you very much for your help!

you very welcome @royjay :slight_smile:

have a nice day