Skip to content

Latest commit

 

History

History
102 lines (76 loc) · 3.39 KB

HOSTING.md

File metadata and controls

102 lines (76 loc) · 3.39 KB

Self-Hosting

esm.sh provides a global fast CDN publicly which is powered by Cloudflare. You can also host esm.sh service by yourself. To do this, please follow the instructions below.

Recommended Host Machine Requirements

  • Linux system (Debian/Ubuntu)
  • 4x CPU cores or more
  • 8GB RAM or more
  • 100GB disk space or more

Clone the Source Code

git clone https://github.com/esm-dev/esm.sh
cd esm.sh

Configuration

To configure the server, create a config.json file then pass it to the server bootstrap command. For example:

// config.json
{
  "port": 8080,
  "npmRegistry": "https://registry.npmjs.org/",
  "npmToken": "******"
}

You can find all the server options in config.example.jsonc.

Run the Server Locally

You will need Go 1.22+ to compile and run the server.

go run main.go --config=config.json

Then you can import React from http://localhost:8080/react.

Deploy the Server to a Single Machine

You can deploy the server to a single machine with the deploy.sh script.

# first time deploy
./scripts/deploy.sh --init
# update the server
./scripts/deploy.sh

Deploy with Docker

Docker Image

esm.sh provides a Docker image for deployment. You can pull the container image from https://ghcr.io/esm-dev/esm.sh.

docker pull ghcr.io/esm-dev/esm.sh      # latest version
docker pull ghcr.io/esm-dev/esm.sh:v136 # specific version

Run the container:

docker run -p 80:80 \
  -e NPM_REGISTRY=https://registry.npmjs.org/ \
  -e NPM_TOKEN=****** \
  ghcr.io/esm-dev/esm.sh:latest

Available environment variables:

  • COMPRESS: Compress http responses with gzip/brotli, default is true.
  • CUSTOM_LANDING_PAGE_ORIGIN: The custom landing page origin, default is empty.
  • CUSTOM_LANDING_PAGE_ASSETS: The custom landing page assets separated by comma(,), default is empty.
  • CORS_ALLOW_ORIGINS: The CORS allow origins separated by comma(,), default is allow all origins.
  • LOG_LEVEL: The log level, available values are ["debug", "info", "warn", "error"], default is "info".
  • MINIFY: Minify the built JS/CSS files, default is true.
  • NPM_QUERY_CACHE_TTL: The cache TTL for NPM query, default is 10 minutes.
  • NPM_REGISTRY: The global NPM registry, default is "https://registry.npmjs.org/".
  • NPM_TOKEN: The access token for the global NPM registry.
  • NPM_USER: The access user for the global NPM registry.
  • NPM_PASSWORD: The access password for the global NPM registry.
  • SOURCEMAP: Generate source map for built JS/CSS files, default is true.
  • STORAGE_TYPE: The storage type, available values are ["fs", "s3"], default is "fs".
  • STORAGE_ENDPOINT: The storage endpoint, default is "~/.esmd/storage".
  • STORAGE_REGION: The region for S3 storage.
  • STORAGE_ACCESS_KEY_ID: The access key for S3 storage.
  • STORAGE_SECRET_ACCESS_KEY: The secret key for S3 storage.

You can also create your own Dockerfile based on ghcr.io/esm-dev/esm.sh:

FROM ghcr.io/esm-dev/esm.sh:latest
ADD ./config.json /etc/esmd/config.json
CMD ["esmd", "--config", "/etc/esmd/config.json"]