Run things locally by http-server

Hey guys,

I ran my file by open it in Firefox but today it doesn’t work because of this warning I guess:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///E:/Programming/Unity/Projects/Nestables/three-js/assets/ThreeJS/models/block/grass_block.gltf. (Reason: CORS request not http)

BTW I want to run local server and run my html file on it.
I try to use nodejs for it.
I follow all the things here but it doesn’t run it in the browser.
This is a log in cmd: "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"

Where is the problem ?

1 Like

It’s not possible to say that with your information provided so far. It’s probably best if you share your project as a github repository so we can debug it locally.

BTW: Instead of installing a http server globally, it’s better to organize your project as a npm package. You then add http-server as a dev dependency and create a script entry in the package.json file in order to start your http server. Something like:

"scripts": {
    "dev": "http-server -c-1"

You can then start the server by executing npm run dev in the console.

1 Like

@ATHellboy Have you tried moving all your files inside public folder?

When executed http-server command will serve stuff from this folder.

So I struggled with this exact problem for a while, I think your problem is related with this issue:
http-server #525

Instead of requesting localhost:8080 also specify the file path index.html

localhost:8080/index.html and you should be able to load the page correctly.

1 Like