Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@commercetools-frontend/mc-http-server

16.12.0 • Public • Published

@commercetools-frontend/mc-http-server

Latest release (latest dist-tag) Latest release (next dist-tag) Minified + GZipped size GitHub license

This package contains the HTTP server to run a MC application in production.

This server should only be used for production, for development we use @commercetools-frontend/mc-scripts to start a development server.

Install

$ npm install --save @commercetools-frontend/mc-http-server

Docker image

We also provide a docker image to run the server:

$ docker run -p 3001:3001 eu.gcr.io/ct-images/mc-http-server:v0.0.0 mc-http-server --config="$(pwd)/env.json"

Why do we need an HTTP Server?

Since a SPA consists of mainly JS bundles and CSS, it's usually not necessary to have an actual HTTP server running. In theory it's enough to serve a static HTML page from e.g. a CDN.

However our MC SPA requires certain information and configuration which cannot be provided on compile time ([*][#inject-variables-at-compile-time]). This information is available at runtime through environment variables, which needs to by dynamically injected into the index.html.

For that reason, before the server starts, we pull the index.html.template generated on build time (containing references to the JS bundles and placeholders for runtime variables to be injected) and generate the final index.html.

All static assets are served from the public folder.

Additional responsibilities

Besides generating and serving the index.html, the HTTP server does additionally a couple of things:

  • gathers /metrics for Prometheus
  • provides a /version endpoint with the current revision hash (git SHA)

Install

npm i @commercetools-frontend/mc-http-server

DownloadsWeekly Downloads

2,175

Version

16.12.0

License

MIT

Unpacked Size

20.5 kB

Total Files

11

Last publish

Collaborators

  • avatar
  • avatar
  • avatar