Skip to content
Snippets Groups Projects
Select Git revision
  • b64987d2dd4c4fa21c41d72bbef72b51fb36bd8b
  • master default protected
  • hacktoberfest-2025-update
  • gh-pages
  • dependabot/npm_and_yarn/path-to-regexp-8.3.0
  • dependabot/npm_and_yarn/nock-14.0.10
  • dependabot/npm_and_yarn/react-19.1.1
  • dependabot/npm_and_yarn/react-dom-19.1.1
  • server-2025-08-01-57ada99c
  • server-2025-02-01-6100669a
  • server-2024-11-01-87cba042
  • server-2024-10-01-6875b7c8
  • server-2024-09-01-3d52575c
  • daily-tests-gha2
  • daily-tests-gha
  • server-2023-12-01-92d8fb8e
  • server-2023-11-01-a80c93fd
  • server-2023-10-01-31096085
  • coc-v2
  • server-2023-09-01-8edc3810
  • server-2023-08-01-75858a03
  • server-2025-09-02
  • server-2025-09-01
  • server-2025-08-03
  • server-2025-07-01
  • 5.0.2
  • 5.0.1
  • 5.0.0
  • server-2025-06-01
  • server-2025-05-01
  • server-2025-04-03
  • server-2025-03-02
  • server-2025-03-01
  • server-2025-02-02
  • server-2025-01-01
  • server-2024-12-01
  • server-2024-11-02
  • 4.1.0
  • server-2024-09-25
  • server-2024-09-02
  • server-2024-08-01
41 results

self-hosting.md

Blame
  • user avatar
    Joschua Becker authored and GitHub committed
    Node.js 8.x LTS Carbon is no longer actively supported!
    
    Co-authored-by: default avatarrepo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
    b2bb5023
    History

    Hosting your own Shields server

    Installation

    You will need Node 8 or later, which you can install using a package manager.

    On Ubuntu / Debian:

    curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -; sudo apt-get install -y nodejs
    git clone https://github.com/badges/shields.git
    cd shields
    npm ci  # You may need sudo for this.

    Build the frontend

    npm run build

    Start the server

    sudo node server

    The server uses port 80 by default, which requires sudo permissions.

    There are two ways to provide an alternate port:

    PORT=8080 node server
    node server 8080

    The root gets redirected to https://shields.io.

    For testing purposes, you can go to http://localhost/.

    Heroku

    Once you have installed the Heroku CLI

    heroku login
    heroku create your-app-name
    git push heroku master
    heroku open

    Docker

    You can build and run the server locally using Docker. First build an image:

    $ docker build -t shields .
    Sending build context to Docker daemon 3.923 MB
    
    Successfully built 4471b442c220

    Optionally, create a file called shields.env that contains the needed configuration. See server-secrets.md and config/custom-environment-variables.yml for examples.

    Then run the container:

    $ docker run --rm -p 8080:80 --name shields shields
    # or if you have shields.env file, run the following instead
    $ docker run --rm -p 8080:80 --env-file shields.env --name shields shields
    
    > gh-badges@1.1.2 start /usr/src/app
    > node server.js
    
    http://[::1]/

    Assuming Docker is running locally, you should be able to get to the application at http://localhost:8080/.

    If you run Docker in a virtual machine (such as boot2docker or Docker Machine) then you will need to replace localhost with the IP address of that virtual machine.

    Raster server

    If you want to host PNG badges, you can also self-host a raster server which points to your badge server. It's designed as a web function which is tested on Zeit Now, though you may be able to run it on AWS Lambda. It's built on the micro framework, and comes with a start script that allows it to run as a standalone Node service.

    • In your raster instance, set BASE_URL to your Shields instance, e.g. https://shields.example.co.
    • Optionally, in your Shields, instance, configure RASTER_URL to the base URL, e.g. https://raster.example.co. This will send 301 redirects for the legacy raster URLs instead of 404's.

    If anyone has set this up, more documentation on how to do this would be welcome! It would also be nice to ship a Docker image that includes a preconfigured raster server.

    Zeit Now

    To deploy using Zeit Now:

    npm run build  # Not sure why, but this needs to be run before deploying.
    now

    Persistence

    To enable Redis-backed GitHub token persistence, point REDIS_URL to your Redis installation.

    Server secrets

    You can add your own server secrets in environment variables or config/local.yml.

    These are documented in server-secrets.md

    Separate frontend hosting

    If you want to host the frontend on a separate server, such as cloud storage or a CDN, you can do that.

    First, build the frontend, pointing GATSBY_BASE_URL to your server.

    GATSBY_BASE_URL=https://your-server.example.com npm run build

    Then copy the contents of the build/ folder to your static hosting / CDN.

    There are also a couple settings you should configure on the server.

    If you want to use server suggestions, you should also set ALLOWED_ORIGIN:

    ALLOWED_ORIGIN=http://my-custom-shields.s3.amazonaws.com,https://my-custom-shields.s3.amazonaws.com

    This should be a comma-separated list of allowed origin headers. They should not have paths or trailing slashes.

    To help out users, you can make the Shields server redirect the server root. Set the REDIRECT_URI environment variable:

    REDIRECT_URI=http://my-custom-shields.s3.amazonaws.com/

    Sentry

    In order to enable integration with Sentry, you need your own Sentry DSN. It’s an URL in format https://{PUBLIC_KEY}:{SECRET_KEY}@sentry.io/{PROJECT_ID}.

    How to obtain the Sentry DSN

    1. Sign up for Sentry
    2. Log in to Sentry
    3. Create a new project for Node.js
    4. You should see Sentry DSN for your project. Sentry DSN can be found by navigating to [Project Name] -> Project Settings -> Client Keys (DSN) as well.

    Start the server using the Sentry DSN. You can set it:

    • by SENTRY_DSN environment variable
    sudo SENTRY_DSN=https://xxx:yyy@sentry.io/zzz node server
    • or by sentry_dsn secret property defined in private/secret.json
    sudo node server

    Prometheus

    Shields uses prom-client to provide default metrics. These metrics are disabled by default. You can enable them by METRICS_PROMETHEUS_ENABLED environment variable.

    METRICS_PROMETHEUS_ENABLED=true npm start

    Metrics are available at /metrics resource.