I have a express server running inside a docker container. Once a user makes a REST call to an endpoint, it should render a scene using Babylon.js, make a screenshot and then create a PDF out of it and return the generated PDF file to the user.
To do so, I am trying to use headless-gl.
As far as I understood, I first need to get the gl context and then pass it to babylon engine:
var gl = require(‘gl’)(1024, 768, { preserveDrawingBuffer: true });
var engine = new BABYLON.Engine(gl, true, {
disableWebGL2Support: true
});
My issue is that I was not able to init the gl and it returns null.
Inside my Dockerfile, I use the following to install the dependencies for xvfb:
RUN apt-get update && apt-get install -y
libgl1-mesa-dri
libglapi-mesa
libosmesa6
mesa-utils
xvfb
&& apt-get clean
My server depends on mongo DB as well so inside my docker-compose.yml file, I wait for the DB container to get initialized before I load my express container:
command: wait-for.sh mongodb:27017 – …/node_modules/.bin/nodemon --inspect=0.0.0.0:9229 ./server.js
I think I need to updated my Dockerfile and docker-compose files with proper commands to load xvfb before running the node application but I am not sure how to do that.
I tried the following along with some other combinations but no luck so far:
command: wait-for.sh mongodb:27017 – xvfb-run -s “-ac -screen 0 1280x1024x24” node ./server.js
I appreciate if someone can help me resolve the issue.