Socket
Book a DemoInstallSign in
Socket

@commercetools-frontend/mc-http-server

Package Overview
Dependencies
Maintainers
3
Versions
413
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools-frontend/mc-http-server

Production HTTP server for running a MC application

latest
Source
npmnpm
Version
16.18.0
Version published
Maintainers
3
Created
Source

@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 Custom 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

Why do we need an HTTP Server?

Since a Single Page Application consists of mainly JavaScript 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, for example from a Content Delivery Network (CDN).

However, the Custom Application requires certain information and configuration which cannot be provided on build time. This information is available at runtime through environment variables, which needs to be dynamically injected into the index.html.

For that reason, before the server starts, we process the index.html.template that was previously generated on build time, containing references to the JavaScript bundles. Additionally, there are some placeholders variables that are replaced with the values from the application config. After that, the final index.html file is written on disk and ready to be served by the HTTP server.

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)

Keywords

javascript

FAQs

Package last updated on 06 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts