iTowns / itowns

A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
http://www.itowns-project.org
Other
1.1k stars 298 forks source link

Fetch without params (as actual examples) leads to 401 Unauthorized error on distant server #580

Closed nosy-b closed 6 years ago

nosy-b commented 6 years ago

When trying to copy the whole itowns repository with its build on a server the JSON files can't be loaded because of Authorization Required 401

Your Environment

Win7/Chrome

Context

It works fine in localhost but when deploying on a standard distant server it can't get the JSON from examples

FIX

An easy fix is to add fetch parameters : {headers: {Accept: 'application/json'}, credentials: 'same-origin'}

Example to load the ortho JSON from Examples

var fetchParams = {headers: {Accept: 'application/json'}, credentials: 'same-origin'};
itowns.Fetcher.json('./layers/JSONLayers/Ortho.json', fetchParams).then(addLayerCb);

Should we add this as default option in the Fetcher class or modify all examples with this default parameters so users don't have bad surprises when deploying iTowns on their servers?

autra commented 6 years ago

I'm quite suprised: it does work on a distant env: www.itowns-project.org (see globe example, it uses some of these json files). I suspect there's something wrong with your environment. How do you serve your files?

nosy-b commented 6 years ago

Yes I was surprised it works on Github.io but not on my server I don't have the hand on it, there is Apache/2.2.16 (Debian) on it that's all the info I have

autra commented 6 years ago

Are you just dropping the files somewhere, or are you using npm start?

nosy-b commented 6 years ago

Ok I know why I have to specify same origin credentials for the fetch! That's because the access to the directory is protected with an indentificaiton. If I place the project on an 'open' directory it works fine without fetch parametrization.