Parse-server in Docker to serve static / ReactJS content

#1

Hi there :slight_smile:

I’ve got a client project running on an old version of parse-server (~2.2.x), deployed to Heroku using the git push mechanism. It was started using the parse-server-example project, so uses Express. This server serves a ReactJS app through a modified index.js file with the following line added:

app.use(express.static('dist'));

I’m trying to upgrade this server to a more recent version, and move it to a Docker-based setup.

My question is, can I achieve the same effect (serving the web content from the same node / parse-server instance) using the vanilla parseplatform/parse-server Docker image, without having to overwrite content in the image?

I’m still fairly new to the node / Javascript ecosystem, so apologies if this question seems silly, makes no sense, or is otherwise offensive :slight_smile:

#2

Well, following the twelve factor architecture you should move this static files to be served from a CDN, like AWS S3 or Google Cloud Storage, etc. You can use a module on your parse-server to use this storage services to save all your “Parse.File” objects, that will give you the url of each file automatically.

On the other hand the react app need to be updated too, to get theses files from Parse.

So, don’t host the static content or any persistent content on the same Docker container of your parse-server.
You can read more here: https://12factor.net/

#3

It’s definitely not the ideal setup. Unfortunately ‘the right way’ isn’t always an option.

Having toyed with the problem in the time since I wrote this, I think the best way of moving from parse-server-example to a Dockerized setup is just to build from the Dockerfile provided in the repo.

The only thing I’ve noticed that’s kind of a pain is that the environment variable names seem incompatible between parse-server-example and the official parse-server Docker image.

@flovilmart are these naming differences on purpose, or would there be interest in having the naming of these variables aligned between deployment methods?

#4

I’m not sure what you mean by differences. parse-server-example is an abomination and it should never have been released this way. Just use parse-server and provide the appropriate environment variables

#5

Yeah unfortunately the project was built on parse-server-example (wasn’t me). The issue is serving static content from the same node instance as the running parse-server (again… wasn’t me); as far as I can tell I can’t achieve this through environment variables?

And as to the differences, for instance the parse-server-example looks for an environment variable APP_ID, where the Docker image looks for PARSE_SERVER_APPLICATION_ID.

#6

No but you can pass a configuration in the form
Of a JavaScript module, and use the ‘middleware’ parameter in order to inject an express middleware before parse-server.

From the Docker image; you can also override the entrypoint / command with the appropriate code. I don’t have example to share though

1 Like