Running Locally
The Babel Licensing Web Application can be configured to run on your local machine while connecting to a remote Babel Licensing Service. This setup provides several advantages, including improved development workflows, testing capabilities, and the ability to maintain a centralized licensing database while allowing distributed access through local web interfaces.
Configuration Method
The Babel Licensing Web Application is configured to connect to a remote service using a runtime configuration file.
Runtime Configuration via config.js
The Babel Licensing Web Application now uses a config.js file located in the web application’s root directory to support runtime configuration. This approach is especially useful for:
- Local development environments
- Production deployments where environment variables can’t be set at build time
- Containerized environments where configuration needs to be injected at runtime
- Testing different API endpoints without rebuilding the application
The config.js file provides two methods for configuration:
Method 1: Set Variables Directly
// In config.js or via script
window.BABEL_ENV = {
BABEL_LICENSING_API_URL: 'https://your-remote-server:port',
BABEL_LICENSING_API_KEY: 'your_api_key'
};Method 2: Use the Setup Function
// In config.js or via script
window.BABEL_ENV_SETUP({
apiUrl: 'https://your-remote-server:port',
apiKey: 'your_api_key'
});Remote Server Kestrel Configuration
When running the web application locally and connecting to a remote Babel Licensing Service, it’s important to configure the remote server to focus solely on providing API services rather than also serving the web application. This can be achieved by modifying the appsettings.json file on the remote server:
"Application": {
"EnableWebApi": true,
"EnableWebUI": false
}Setting EnableWebUI to false prevents the remote server from serving the web application, ensuring that it only provides API functionality. This configuration optimizes resource usage on the remote server and prevents potential conflicts when running the web UI locally.
API Key Generation
The API key must be generated on the remote Babel Licensing Service. To generate an API key:
- Access the remote Babel Licensing Service’s administration interface
- Navigate to the “API Keys” section
- Create a new API key with appropriate permissions
- Copy the generated key for use in your local configuration
Ensure that the API key has sufficient permissions to perform necessary operations through the web application.
Creating a Docker Container with Custom Configuration
Docker provides an excellent way to quickly deploy and serve web applications with custom configuration. The following guide shows you how to create a Docker container that serves the web application with your specific configuration.
Prerequisites
Before starting, ensure you have:
- Docker Desktop installed and running on your system
- Access to the Babel Licensing Web Application files
Step 1: Modify the config.js File
Locate the existing config.js file in the web application’s root directory and modify it with your specific configuration:
// config.js
window.BABEL_ENV = {
BABEL_LICENSING_API_URL: 'https://your-remote-server:port',
BABEL_LICENSING_API_KEY: 'your_api_key'
};
// Alternatively, you can use the setup function
/*
window.BABEL_ENV_SETUP({
apiUrl: 'https://your-remote-server:port',
apiKey: 'your_api_key'
});
*/Step 2: Create a Dockerfile
Create a file named Dockerfile (with no extension) with the following content:
FROM nginx:alpine
# Remove default Nginx static assets
RUN rm -rf /usr/share/nginx/html/*
# Copy the content of wwwroot to the Nginx html directory
COPY ./wwwroot /usr/share/nginx/html
# Expose port 80
EXPOSE 80
# Run Nginx in the foreground
CMD ["nginx", "-g", "daemon off;"]This Dockerfile uses the lightweight Alpine-based Nginx image, which is excellent for serving static web content. It copies the web application files into the Nginx server’s web root, including the modified config.js file.
Step 3: Build the Docker Image
Open a terminal or command prompt in the directory containing your Dockerfile and the web application files, then run:
docker build -t babel-webapp .This command builds a Docker image named “babel-webapp” using the current directory (denoted by the dot) as the build context.
Step 4: Run the Docker Container
After building the image, start a container with:
docker run -d -p 8080:80 --name babel-licensing-webapp babel-webappThis command:
- Runs the container in detached mode (
-d) - Maps port 8080 on your host to port 80 in the container (
-p 8080:80) - Names the container “babel-licensing-webapp” for easy reference
- Uses the “babel-webapp” image we created earlier
Step 5: Access Your Web Application
Open a web browser and navigate to:
http://localhost:8080You should see your web application being served from the Docker container.
Managing Your Container
- To stop the container:
docker stop babel-licensing-webapp - To start it again:
docker start babel-licensing-webapp - To remove the container:
docker rm babel-licensing-webapp - To view logs:
docker logs babel-licensing-webapp
Verifying Connection
After configuring the application through the config.js file, you can verify that your local web application is correctly connecting to the remote service:
- Start the Babel Licensing Web Application
- Navigate to the dashboard or any page that requires data from the licensing service
- Check for successful data retrieval and no connection errors
- You can also check the application logs for any connection-related messages
Troubleshooting
If you encounter issues connecting to the remote service:
- Check Configuration:
- Open the browser console and verify that
config.jsis loaded correctly - Confirm that the API URL and key are properly set in the configuration
- Open the browser console and verify that
- Check Network Connectivity: Confirm that your local machine can reach the remote server (try using
pingor similar tools) - Validate API Key: Ensure the API key is valid and has the necessary permissions
- Check SSL/TLS: If using HTTPS, verify that the SSL certificate is valid and trusted
- Firewall Settings: Ensure that your firewall allows outbound connections to the remote service port
- Check Service Health: Use the health check endpoint (
/health) on the remote service to verify it’s operational - Browser Console: Check for any JavaScript errors in the browser console that might indicate configuration issues
Security Considerations
When connecting to a remote licensing service, consider these security best practices:
- Use HTTPS for secure communication
- Regularly rotate API keys
- Apply the principle of least privilege when assigning permissions to API keys
- Do not commit configuration files with API keys to source control
- For production deployments:
- Use environment-specific config files
- Consider using a secure vault service for storing sensitive credentials
- Implement runtime configuration injection for containerized environments
By following these configuration steps, you can successfully run the Babel Licensing Web Application locally while leveraging a centralized remote Babel Licensing Service for data management and licensing operations.