Gltf files not loading in production

Hi guys!

So I’m having a strange issue, hoping someone can help me :slight_smile:

So I’m running a CRA. My gltf files are in the public folder.
I’m importing files as follows…

 SceneLoader.ImportMesh(
    "",
    `${process.env.PUBLIC_URL}/assets/Shooter/`,
    "Export_players_03.gltf",
    scene,
    function (meshes) {
      ...
    }
  );

This works fine locally. I can see that the network request is going to localhost/assets/Shooter/Export_players_03.gltf
and the response is the gltf file as expected.

I’ve deployed the app to AWS Amplify. The app builds and deploys successfully, but doesn’t load the gltf file. I get an error…

Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse

The network call seems to be going to the right place…
newAmplifyDomain/assets/Shooter/Export_players_03.gltf

But it’s returning html in the response!

Can anyone give me any insight as to why this is happening?!

Thank you!!!

What does the text say in the html response? It should tell you what the problem is.

Have a look at the network tools - I suspect you are not loading from correct URL and that your model is being served as index.html page contents.

did you set the homepage in your package.json?

edit: now that I read again your question it looks like AWS Amplify is not serving the gltf and I don’t know how to resolve that.

cloudflare pages is free and has unlimited data. https://pages.cloudflare.com/ . I say again, unlimited edge cdn bandwidth for free. Ignore all the marketing shit about collaborative builds and previews, pointless. Anyway, it will also fix your url problem.

You could also try removing the process variable and using window.location.host. Location: host - Web APIs | MDN

1 Like

Cheers guys - was down to Amplify, have sorted it.
For anyone else - in the rewrites and redirects section of Amplify - you have to tell it to redirect all requests for X file type to index.html as the app is supposed to load all assets itself.
Should look something like this…

2 Likes