This is a Node.js application that uses Express.js for the server, WebSocket for real-time communication, and EJS for rendering HTML. The main purpose of this application is to make log files accessible over HTTP.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Node.js
- yarn or npm
-
Clone the repository
git clone [email protected]:zauberware/weblogger.git
-
Navigate into the cloned repository
cd weblogger
-
Install the dependencies
yarn install
-
Start the server
yarn start # or yarn dev to start with nodemon
The server will start on port 3000, or on the port specified in your environment variables.
The application serves static files from the public
directory. You can access these files by navigating to http://localhost:3000/<filename>
.
The main feature of this application is the ability to view log files over HTTP. The application reads from two log files: access.log
and error.log
. These file paths can be configured using the INFO_LOG
and ERROR_LOG
environment variables, respectively.
Note: The server requires read and write permissions on the error.log
and access.log
files.
For production environments, we recommend using PM2, a production process manager for Node.js applications.
You can install PM2 globally on your system by running the following command:
npm install pm2 -g
Once PM2 is installed, you can start your application with the following command:
pm2 start app.js
Replace app.js
with the entry point to your application if it's different.
-
To view the status of your applications:
pm2 status
-
To restart an application:
pm2 restart app_name_or_id
-
To stop an application:
pm2 stop app_name_or_id
-
To view detailed metrics and logs for your application:
pm2 monit
Remember to replace app_name_or_id
with the name or id of your application as listed in pm2 status
.
For more information on how to use PM2, refer to the official PM2 documentation.
For production environments, we recommend using Nginx as a reverse proxy for your application. Here's a basic configuration that you can use:
server {
listen 80;
server_name logs.yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Replace yourdomain.com
with your actual domain name and http://localhost:3000
with the URL where your application is running.
This configuration tells Nginx to listen on port 80 for incoming connections for yourdomain.com
and to forward those connections to your application running on http://localhost:3000
.
Remember to reload or restart Nginx after you make changes to the configuration:
sudo systemctl reload nginx
For more information on how to configure Nginx, refer to the official Nginx documentation.
Config Variable | Default Value | Description |
---|---|---|
PORT |
3000 |
The port on which the server will run. |
INFO_LOG |
'access.log' |
The path to the access log file. |
ERROR_LOG |
'error.log' |
The path to the error log file. |
WEBSOCKET_URL |
'ws://localhost:${PORT}' |
The URL for the WebSocket connection. |
BASIC_AUTH |
false |
Enable or disable basic authentication. |
BASIC_AUTH_USERNAME |
admin |
The username for basic authentication. |
BASIC_AUTH_PASSWORD |
admin |
The password for basic authentication. |
NODE_ENV |
'development' |
The environment in which the server is running. Can be 'development' , 'production' , etc. |
CORS |
true |
Enable or disable CORS. |
CORS_ORIGINS |
undefined |
Comma-separated list of allowed origins. If not defined and NODE_ENV is 'development', all origins are allowed. |
DEBUGMODE |
false |
Enable or disable debug mode. |
- Node.js
- Express.js - Web framework for Node.js
- express-basic-auth - Simple username and password authentication for Express.js
- WebSocket - WebSocket implementation for Node.js
- EJS - Embedded JavaScript templating
- CORS
- dotenv
- read-last-lines
The favicon for this application was generated using the following graphics from Twitter Twemoji:
- Graphics Title:
1f5d2.svg
- Graphics Author: Copyright 2020 Twitter, Inc and other contributors. Graphics Source can be found here.
- Graphics License: CC-BY 4.0
This project is licensed under the MIT License - see the LICENSE.md file for details.
Built with ❤️ by zauberware technologies