Skip to content

Deploying an Anchr App

Introduction

Anchr is a lightweight, open-source toolbox for everyday tasks on the internet. It offers three core features:

  • Link shortening – create short, shareable URLs with optional malicious-link checking via Google Safe Browsing.
  • Bookmark collections – searchable, categorized bookmark lists accessible from any device.
  • Encrypted image uploads – share images securely with client-side encryption.

Built on Node.js with an AngularJS frontend and MongoDB backend, Anchr is ideal for personal or team use when you want full control over your data. Deploying Anchr on Klutch.sh gives you automated builds from GitHub, managed secrets, persistent storage for uploads, and hassle-free HTTPS—no server maintenance required.

This guide walks you through deploying Anchr on Klutch.sh using a Dockerfile, configuring the required MongoDB database, setting up environment variables, attaching persistent volumes, and verifying the deployment.


Features overview

FeatureDescription
Link shortenerGenerate compact URLs; optionally verify against Safe Browsing API
Bookmark collectionsOrganize links by category with full-text search
Encrypted imagesUpload images with client-side AES encryption
OAuth loginGoogle and Facebook authentication support
Telegram botInteract with Anchr via @AnchrBot
Prometheus metricsExpose /api/metrics for monitoring
REST APIIntegrate with ShareX, browser extensions, and custom scripts

Prerequisites

Before you begin, ensure you have:

  • A Klutch.sh account
  • A GitHub repository (fork or clone of the official Anchr repo)
  • A running MongoDB instance (deploy on Klutch.sh or use a managed service like MongoDB Atlas)
  • Basic familiarity with Docker and environment variables
  • (Optional) A Google API key for Safe Browsing link checks
  • (Optional) OAuth credentials for Google or Facebook login

Architecture overview

Anchr consists of:

ComponentTechnologyNotes
BackendNode.js 21, ExpressServes API and static frontend
FrontendAngularJS, BowerBuilt during Docker image creation
DatabaseMongoDB 6+Stores users, links, collections, images metadata
StorageFile systemUploaded images written to /app/data

The application listens on port 3000 by default. On Klutch.sh, you’ll set this as the internal port to route HTTP traffic.


Deployment steps

  1. Prepare your GitHub repository

    Fork or clone the Anchr repository to your own GitHub account. The repo already includes a production-ready Dockerfile, so no changes are needed for basic deployments.

    Terminal window
    git clone https://github.com/muety/anchr.git
    cd anchr
    git remote set-url origin https://github.com/YOUR_USERNAME/anchr.git
    git push -u origin master

    Klutch.sh automatically detects the Dockerfile in the repository root and uses it for the build—no manual selection is required.

  2. Deploy MongoDB on Klutch.sh (or use an external database)

    Anchr requires MongoDB. You can either use a managed service like MongoDB Atlas or deploy MongoDB on Klutch.sh as a separate app.

    1. Create a free cluster at MongoDB Atlas.
    2. Add a database user and whitelist your Klutch.sh app’s IP (or allow access from anywhere for simplicity).
    3. Copy the connection string (e.g., mongodb+srv://user:pass@cluster.mongodb.net/anchr).

    Option B: Deploy MongoDB on Klutch.sh

    1. In klutch.sh/app, create a new app within your project.
    2. Connect a GitHub repo containing a simple MongoDB Dockerfile:
    FROM mongo:6
    EXPOSE 27017
    CMD ["mongod", "--bind_ip_all"]
    1. Select TCP traffic and set the internal port to 27017.
    2. Attach a persistent volume with mount path /data/db and size 20 GB (adjust based on expected data).
    3. Deploy the app. You can connect to the database at your-mongo-app.klutch.sh:8000 from your Anchr app.
  3. Create a new Anchr app on Klutch.sh

    1. Log in to klutch.sh/app.
    2. Create a new project (if you don’t have one) by clicking New Project.
    3. Inside your project, click New App.
    4. Connect your GitHub repository containing the Anchr source code.
    5. Klutch.sh will detect the Dockerfile automatically and begin building.
  4. Configure environment variables

    In the Klutch.sh dashboard, navigate to your Anchr app’s Settings → Environment Variables and add the following. Mark sensitive values (passwords, secrets, API keys) as secrets.

    Required variables:

    Terminal window
    # Server
    PORT=3000
    LISTEN_ADDR=0.0.0.0
    ANCHR_PUBLIC_URL=https://example-app.klutch.sh
    # Database (adjust host/port based on your MongoDB setup)
    ANCHR_DB_HOST=your-mongo-app.klutch.sh
    ANCHR_DB_PORT=8000
    ANCHR_DB_NAME=anchr
    ANCHR_DB_USER=anchr
    ANCHR_DB_PASSWORD=your-secure-password
    # Uploads & logs
    ANCHR_UPLOAD_DIR=/app/data
    ANCHR_LOG_PATH=/app/data/logs/access.log
    ANCHR_ERROR_LOG_PATH=/app/data/logs/error.log
    # Security
    ANCHR_SECRET=generate-a-long-random-string

    Optional variables:

    Terminal window
    # Google Safe Browsing (link safety checks)
    ANCHR_GOOGLE_API_KEY=your-google-api-key
    # OAuth (Google login)
    ANCHR_GOOGLE_CLIENT_ID=your-google-client-id
    ANCHR_GOOGLE_SECRET=your-google-client-secret
    # OAuth (Facebook login)
    ANCHR_FB_CLIENT_ID=your-facebook-client-id
    ANCHR_FB_SECRET=your-facebook-client-secret
    # User registration
    ANCHR_ALLOW_SIGNUP=true
    ANCHR_VERIFY_USERS=false
    # Monitoring
    ANCHR_EXPOSE_METRICS=true
    # SMTP for email verification (if ANCHR_VERIFY_USERS=true)
    ANCHR_SMTP_HOST=smtp.example.com
    ANCHR_SMTP_PORT=587
    ANCHR_SMTP_USER=your-smtp-user
    ANCHR_SMTP_PASS=your-smtp-password
    ANCHR_MAIL_SENDER=Anchr <noreply@example.com>
  5. Configure the internal port

    In your Anchr app’s settings:

    1. Select HTTP traffic.
    2. Set the internal port to 3000 (Anchr’s default).

    Klutch.sh will route external HTTPS traffic to port 3000 inside your container.

  6. Attach persistent storage

    Anchr stores uploaded images on the file system. To persist these across deployments:

    1. Navigate to Storage in your app’s settings.
    2. Click Add Volume.
    3. Configure:
      • Mount path: /app/data
      • Size: 50 GB (adjust based on expected uploads)
    4. Save the volume.

    This ensures uploaded images, logs, and any other data written to /app/data survive container restarts and redeployments.

  7. Deploy the application

    1. Push any final changes to your GitHub repository.
    2. In the Klutch.sh dashboard, click Deploy (or trigger a redeploy if already created).
    3. Monitor the build logs for any errors.
    4. Once the build completes, your Anchr instance will be available at https://example-app.klutch.sh.
  8. Verify the deployment

    1. Open https://example-app.klutch.sh in your browser.
    2. You should see the Anchr login/signup page.
    3. Create an account (if ANCHR_ALLOW_SIGNUP=true).
    4. Test each feature:
      • Create a shortlink and verify it redirects.
      • Add a bookmark collection.
      • Upload an image (optionally with encryption).
    5. If you enabled metrics, verify at https://example-app.klutch.sh/api/metrics.

Sample Dockerfile

The official Anchr repository includes a Dockerfile. Here’s a reference version with explanations:

FROM node:21-alpine
WORKDIR /app
# Copy application files
COPY app /app/app/
COPY config /app/config/
COPY lib /app/lib/
COPY public /app/public/
COPY *.js /app/
COPY *.json /app/
# Create data volume mount point
VOLUME [ "/app/data" ]
# Install dependencies
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh
# Install Bower globally and project dependencies
RUN npm install -g bower && \
npm install && \
cd public && \
bower install --allow-root && \
cd .. && \
npm run build && \
mkdir -p /var/log/anchr /app/data/logs
# Expose default port
EXPOSE 3000
# Start production server
ENTRYPOINT ["npm", "run", "production"]

Key points:

  • Uses Node.js 21 Alpine for a lightweight image.
  • Installs Bower (legacy dependency manager still used by Anchr’s frontend).
  • Builds frontend assets during image creation for faster startup.
  • Creates log directories at build time.
  • Exposes port 3000 (Anchr’s default).

Environment variables reference

VariableDefaultDescription
PORT3000TCP port the server listens on
LISTEN_ADDR127.0.0.1IP address to bind (use 0.0.0.0 in containers)
ANCHR_PUBLIC_URLhttp://localhost:3000Public URL (no trailing slash)
ANCHR_DB_HOSTlocalhostMongoDB host
ANCHR_DB_PORT27017MongoDB port
ANCHR_DB_NAMEanchrDatabase name
ANCHR_DB_USERanchrDatabase user
ANCHR_DB_PASSWORDDatabase password (required)
ANCHR_UPLOAD_DIR/var/data/anchrDirectory for uploaded images
ANCHR_SECRETshhhJWT signing secret (use a long random string)
ANCHR_LOG_PATH/var/log/anchr/access.logAccess log file path
ANCHR_ERROR_LOG_PATH/var/log/anchr/error.logError log file path
ANCHR_GOOGLE_API_KEYGoogle Safe Browsing API key
ANCHR_ALLOW_SIGNUPtrueAllow new user registrations
ANCHR_VERIFY_USERStrueRequire email verification
ANCHR_EXPOSE_METRICSfalseExpose Prometheus metrics endpoint

Persistent storage paths

Mount pathPurposeRecommended size
/app/dataUploaded images and logs50–100 GB
/data/db (MongoDB app)Database files20–50 GB

Connecting Anchr to MongoDB on Klutch.sh

If you deployed MongoDB as a separate Klutch.sh app with TCP traffic:

  1. Note your MongoDB app’s URL (e.g., my-mongo.klutch.sh).
  2. The external port for TCP apps is 8000.
  3. Set these environment variables in your Anchr app:
Terminal window
ANCHR_DB_HOST=my-mongo.klutch.sh
ANCHR_DB_PORT=8000

Ensure the MongoDB app has authentication enabled and a user created for the anchr database.


Troubleshooting

SymptomSolution
MongoServerError: Authentication failedVerify ANCHR_DB_USER and ANCHR_DB_PASSWORD match the MongoDB user credentials.
Uploads lost after redeployEnsure /app/data is mounted to a persistent volume.
EADDRINUSE: address already in useCheck that PORT matches the internal port configured in Klutch.sh (default 3000).
Shortlinks not createdIf using Safe Browsing, verify ANCHR_GOOGLE_API_KEY is valid.
Email verification not sendingConfigure SMTP variables or disable verification with ANCHR_VERIFY_USERS=false.
Build fails on Bower installThe Dockerfile handles this; ensure you’re using the official Dockerfile without modifications.

Security best practices

  • Generate strong secrets: Use a long, random string for ANCHR_SECRET.
  • Use Klutch.sh secrets: Mark database passwords and API keys as secrets in the environment variables UI.
  • Restrict signups: Set ANCHR_ALLOW_SIGNUP=false after creating your account if you don’t want public registrations.
  • Enable HTTPS: Klutch.sh provides automatic HTTPS for all deployed apps.
  • Rotate credentials: Periodically update database passwords and JWT secrets.

Next steps