Giter Club home page Giter Club logo

docker-static-webserver's People

Contributors

nstapelbroek avatar rick-nu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

docker-static-webserver's Issues

Environment variable replacement potentionally breaks optimized/minimized javascript exports

What

I've ran into an issue where I thought Vite and NextJS weren't exporting files correctly. The browser was throwing exceptions when loading javascript resources.

After lots of debugging, I figured that the site only breaks whilst I was running it in the static -webserver. That got my suspicion going with the environment variable replacement.

Diagnosis

This container replaces all variables with the following pattern: ${MY_ENVIRONMENT_VARIABLE}. So I started searching for ${ in my static exported javascript files. It might not be a surprise anymore that modern javascript can use variables in backtick strings:

const string = `a string with a ${variable}`;

In recent exports, backtick strings became supported in all browsers, and this this is now valid browser compatible javascript.

Another finding was that empty variables also got replaced. So ${} was just replaced with nothing.

Desired solution

We might want to release a new version with different environment variable replacement. Options are:

  • Only replace environment variables with a specific prefix, and put those as a filter in the envsubst command
  • Find a different replacement method, and use ![[MY_ENVIRONMENT_VARIABLE]] or something like that
  • Add a variable that lists all the environment variables that should be replaced (whitelist)

My workaround

How I solved it now in my personal project, was by overwriting 40-envsubst-on-www.sh in the dockerfile, putting:

# Only replace variables in .html, .xml and .txt files
find "$www_dir" -regex '.*\.\(html\|xml\|txt\)$' -type f -exec sh -c 'envsubst < $0 > $0.tmp && mv $0.tmp $0' {} \;

Seperate vhost config from nginx

i needed to overwrite some configuration in the vhost but in the current setup this requires a complete overwrite of nginx.conf

Blocking issues before v4

  • permission denied error when copying files as nginx to /var/www
  • every file is copied on startup. should only be files that match an environment variable

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.