HUB
Sign inSign up

bramkel/node-web-app

By bramkel

•Updated over 2 years ago

Node.js server for dynamic meta tags, by providing a custom API route defining the details.

Image
API management
Web servers
Web analytics
0

803

bramkel/node-web-app repository overview

⁠Dynamic Meta Tags Node Server

This Docker image provides a Node.js server designed to dynamically inject meta tags into your HTML files, enhancing SEO and link previews when sharing URLs. It's perfect for any single-page application built with React or similar frameworks.

⁠Features:

  • Dynamic Meta Tags: Fetches and injects meta tags such as title, description, and image from an external API.
  • Static File Serving: Serves static resources with caching enabled for 30 days.
  • Environment Configuration: Easily configure API URL, default meta tags, and static file paths via environment variables.

⁠Environment Variables:

  • API_URL - URL of the API to fetch meta tags from.
  • ROOT_PATH - Path to the directory containing index.html and static files (default: /app).
  • DEFAULT_TITLE - Default title for the website.
  • DEFAULT_DESCRIPTION - Default description for the website.

⁠API route

You need to provide an API route that the server can query to fetch meta tags. The server sends a request to the API with the encoded URL of the current request. The API should return a JSON object containing the meta tags.

⁠Example request

Assume the incoming request URL is https://example.com/page1⁠. The server will encode this URL and make a request to the API:

GET https://api.example.com/meta?path=aHR0cHM6Ly9leGFtcGxlLmNvbS9wYWdlMQ==

Here, aHR0cHM6Ly9leGFtcGxlLmNvbS9wYWdlMQ== is the base64 encoding of https://example.com/page1⁠.

⁠Expected JSON Response

The API should return a JSON object containing the meta tags for the requested URL:

{
  "title": "Page Title",
  "description": "Page Description",
  "image": "https://example.com/image.jpg",
  "icon": "https://example.com/favicon.ico"
}
  • title (string, optional) - The title of the page.
  • description (string, optional) - The description of the page.
  • image (string, optional) - The URL of the image to be used in the meta tags.
  • icon (string, optional) - The URL of the favicon to be used.

⁠Example usage

⁠Docker compose
version: '3.8'

services:
  frontend:
    hostname: frontend
    image: bramkel/node-web-app:latest
    container_name: "frontend-container"
    restart: unless-stopped
    ports:
      - 3000:3000
    environment:
      - DEFAULT_TITLE=My Awesome App
      - DEFAULT_DESCRIPTION=Discover and share the best content.
      - API_URL=https://api.example.com/
    volumes:
      - /path/to/your/app:/react-app

⁠Docker command
docker run -d --name frontend-container -p 3000:3000 \
  -e DEFAULT_TITLE="My Awesome App" \
  -e DEFAULT_DESCRIPTION="Discover and share the best content." \
  -e API_URL="https://api.example.com/" \
  -v /path/to/your/app:/react-app \
  bramkel/node-web-app:latest
Tag summary
Recent tags
Content type
Image
Digest
sha256:3ba65c072…
Size
393.9 MB
Last updated
over 2 years ago
docker pull bramkel/node-web-app:latest