-
Notifications
You must be signed in to change notification settings - Fork 647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Broken rendering - No handling of local GeoJSON files #1324 #1326
Conversation
I'm not sure I would want to take this approach. I kind of liked you other idea of adding a "file://" protocol, where you could set up path for "file" paths like we do for others paths https://tileserver.readthedocs.io/en/latest/config.html#paths For that to work we would need a path set up similar to |
Yes, that behaviour would have been a bit hacky, because it would require a matching environment to work in rendered and vector mode. I extended the code a bit to support a file:// urls, but stumpled over the spec a bit: geojson uses "data" instead of "url" because it seems to be inteded, to write inline geojson. In the current implementation it may be a change with a "bigger" impact, because with /files/ the public interface is extended, but this works without any need of a reverse proxy in both modes. |
I like how this looks better now and will try to test it soon. One thing I was thinking about was an issue we have with the 'icons' path we added. Right now, if you don't specify a path for that it defaults to the tileserver-gl root directory, and in that case allows the user to try and load files in the root directory that are not images and causes a crash. In my own instance I specifically set it to the folder I was wondering if we should do the same thing with 'files' to prevent inadvertently exposing all source files and maybe make a default folder specifically for that like |
For the comment on geojson sources, it seems to accect inline code or a url In my own project I have used dynamically generated geojson sources by url on pages like I guess the only question is does maplibre-native seem to work with this new file:// protocol ? the handler for file:// has been added so I assume it should |
I am testing locally with this config on windows I am starting this with Note, I did make a few changes locally. I changed 'file://' to 'files://' and updated anywhere in the code that just used 'file' to 'files'. This was for consistency with the other protocol and to get it working. I also made the other path change I commented above. |
One thing to note is depending on your geojson file, this is likely going to affect performance in raster tiles because every tile it makes is basically loading the full geojson file. Were if instead you did like I mentioned before and converted your geojson to mbtiles/pmtiles vector files with tippecanoe, it would only need to download the region you are looking at and would be faster, since tippcannoe has already broken your data down into tiles. |
Good point! For my current files it seems not to be a problem, but that should be added as note/kept in mind. I will apply some of the above changes later. Edit: I added the changes and tested my setup, maybe you can test on Windows again? |
|
Dockerfile
Outdated
@@ -107,8 +107,8 @@ COPY --from=builder /usr/src/app /usr/src/app | |||
|
|||
COPY . /usr/src/app | |||
|
|||
RUN mkdir -p /data && chown node:node /data | |||
VOLUME /data | |||
RUN mkdir -p /data /usr/src/app/public/files && chown node:node /data /usr/src/app/public/files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only thing I don't really like is making this folder with the dockerfile . since tileserver-gl can run directly without docker, it would need that folder there in that use case also. So maybe we should either make the directory with a default file inside, of maybe find a way to create it with the package.json npm prepare..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the folder to the repository (and excluded .gitignore files for docker build).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me. this can be removed now right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant can we remove the changes in this file. Since the folder exists we don't need to create it here anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was a bit confused.
In fact the mkdir
for public/files may be removed, but due to the '-p' it does not hurt and ensures, that the path, which will be chown'ed and exposed as volume is really there.
If I remove/change it, I would revert the whole file, because the volume depends on the configuration and everything will still work with the default configuration, because the mount may be applied without a exposed volume of an empty directory. (This may be different, if there was a default config file included in the image.)
In short: It's up to you ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather keep it as it was before since it shouldn't really be needed now,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@acalcutt I merged the latest changes, applied the prettier fixes and finally updated the tests to be executed in the main directory, so no further stubbing should be required. |
@acalcutt: I tidied up a little bit (merge master, lint:*:fix, squash - okimiko@222d6c1). If you want to merge, this may be a bit cleaner than this here. If wanted, I can force push it or we close this here and I create a new, clean PR. |
src/serve_rendered.js
Outdated
@@ -893,13 +893,13 @@ export const serve_rendered = { | |||
// console.log('Handling request:', req); | |||
if (protocol === 'sprites') { | |||
const dir = options.paths[protocol]; | |||
const file = unescape(req.url).substring(protocol.length + 3); | |||
const file = decodeURI(req.url).substring(protocol.length + 3).replaceAll('%2c', ','); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this replacement added for?
replaceAll('%2c', ',')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I did not check the code before. Correct would be to use decodeURIComponent
as counterpart of encodeURIComponent
.
decodeURI
/ encodeURI
does not escape commas, so I added the extra replace after using a style with two fonts configured and receiving ERROR: Font not found: Noto Sans Regular%2cNoto Sans Bold
.
I will fix that later today an force push the squashed commit.
force push or a new PR would be fine with me |
- use 'file://' as indicator for local files - add directory as default directory - serve local files at - add documentation for static file serving - add some minor fixes (icon directory, directory checking, decodeURIComponent, extend error message)
Add general missing handling of local geojson files during rendering (#1324).