RackHD HTTP Server (on-http)
on-http serves as the primary HTTP server component for the RackHD infrastructure management system, providing the web user interface and RESTful API endpoints essential for managing bare-metal hardware. Currently at its stable version 2.60.7, the project exhibits a consistent release cadence with frequent patch updates, indicating active development and maintenance. It is deployed as a standalone application, mandating the presence and correct configuration of external MongoDB and RabbitMQ instances for its operation. Its key differentiators lie in its deep integration with RackHD's capabilities for automated hardware provisioning, discovery, and orchestration, offering a structured API that defaults to version 2.0, with version 1.1 explicitly deprecated. The package also includes built-in tools for generating API documentation, task documentation, and client libraries for various programming languages, facilitating ecosystem integration.
Common errors
-
Error: failed to connect to [localhost:27017]
cause The MongoDB database server is not running or is inaccessible from the on-http server.fixVerify that MongoDB is running and listening on the expected port (default 27017). Check network connectivity and MongoDB configuration settings. -
Failed to connect to RabbitMQ broker: amqp://localhost
cause The RabbitMQ message broker is not running or is inaccessible from the on-http server.fixEnsure the RabbitMQ service is active and listening on its configured port (default 5672). Review RabbitMQ logs for startup issues. -
TypeError: Cannot read property 'defaultBackend' of undefined
cause The `fileService` configuration key, or its sub-keys like `defaultBackend`, are missing or incorrectly defined in the application's configuration files.fixInspect the configuration files (e.g., `./config/default.json` or environment variables) to ensure the `fileService` object exists and contains a `defaultBackend` key with a valid backend string, as well as configurations for all defined backends.
Warnings
- gotcha The `on-http` server requires external MongoDB and RabbitMQ instances to be running and accessible for correct operation. Failure to connect to these services will prevent the server from starting or functioning properly.
- deprecated The 1.1 API for RackHD is officially deprecated. While it may still function, new development and integrations should exclusively target the 2.0 API.
- gotcha The official documentation often shows running `node index.js` with `sudo`. Running Node.js applications as root is generally a security risk and can lead to permission issues with files created by the application. Consider alternative deployment strategies.
- gotcha When debugging Node.js applications, the `node-debug` command is noted to not work well with `on-http`. Instead, `node-inspector` is recommended for GUI-based debugging.
Install
-
npm install on-http -
yarn add on-http -
pnpm add on-http
Imports
- app
import { app } from 'on-http/lib/app'; const app = require('on-http');const { app } = require('on-http/lib/app'); - server
import { server } from 'on-http/lib/app'; const { Server } = require('on-http');const { server } = require('on-http/lib/app'); - nconf
import nconf from 'on-http/lib/config';
const nconf = require('on-http/lib/config');
Quickstart
#!/bin/bash
# NOTE: This quickstart assumes MongoDB and RabbitMQ are already running and accessible
# on their default ports (localhost:27017 for Mongo, localhost:5672 for RabbitMQ).
# Clean existing node_modules and install dependencies
rm -rf node_modules
npm install
# Generate API and task documentation (optional, but good for setup and local access)
npm run apidoc
npm run taskdoc
# Start the on-http server in the background.
# The README shows 'sudo node index.js', which is typically required for system ports or permissions.
# For development, you might adjust permissions or run on a higher port.
sudo node index.js &
SERVER_PID=$!
echo "on-http server started (PID: $SERVER_PID). Waiting for it to become ready..."
sleep 10 # Give the server some time to initialize and connect to dependencies
# Perform basic health checks and access documentation
echo "Accessing RackHD UI and API endpoints:"
# Check the Web UI
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" http://127.0.0.1/ui
echo "- UI expected at http://127.0.0.1/ui"
# Check the API documentation
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" http://127.0.0.1/docs
echo "- API Docs expected at http://127.0.0.1/docs"
# Example: Try to fetch a list of nodes (requires RackHD to have discovered nodes)
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" http://127.0.0.1/api/current/nodes
echo "- API endpoint /api/current/nodes (status 200 means success, data depends on setup)"
# Clean up: Kill the background server process
kill $SERVER_PID
wait $SERVER_PID 2>/dev/null
echo "on-http server (PID: $SERVER_PID) stopped."