doc: first run of module documenter

This commit is contained in:
KernelDeimos
2024-12-03 17:04:05 -05:00
parent ac372204fa
commit 67ab8a1710
3 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
# WebModule
This module initializes a pre-configured web server and socket.io server.
The main service, WebServerService, emits 'install.routes' and provides
the server instance to the callback.
## Services
### SocketioService
SocketioService provides a service for sending messages to clients.
socket.io is used behind the scenes. This service provides a simpler
interface for sending messages to rooms or socket ids.
#### Listeners
##### `install.socketio`
Initializes socket.io
###### Parameters
- `server`: The server to attach socket.io to.
### WebModule
undefined
#### Listeners
### WebServerService
This class, WebServerService, is responsible for starting and managing the Puter web server.
It initializes the Express app, sets up middlewares, routes, and handles authentication and web sockets.
It also validates the host header and IP addresses to prevent security vulnerabilities.
#### Listeners
##### `boot.consolidation`
This method initializes the backend web server for Puter. It sets up the Express app, configures middleware, and starts the HTTP server.
##### `boot.activation`
Starts the web server and listens for incoming connections.
This method sets up the Express app, sets up middleware, and starts the server on the specified port.
It also sets up the Socket.io server for real-time communication.
##### `start.webserver`
This method starts the web server by listening on the specified port. It tries multiple ports if the first one is in use.
If the `config.http_port` is set to 'auto', it will try to find an available port in a range of 4100 to 4299.
Once the server is up and running, it emits the 'start.webserver' and 'ready.webserver' events.
If the `config.env` is set to 'dev' and `config.no_browser_launch` is false, it will open the Puter URL in the default browser.
##### `start.webserver`

View File

@@ -1,10 +1,20 @@
const BaseService = require('../../services/BaseService');
/**
* SocketioService provides a service for sending messages to clients.
* socket.io is used behind the scenes. This service provides a simpler
* interface for sending messages to rooms or socket ids.
*/
class SocketioService extends BaseService {
static MODULES = {
socketio: require('socket.io'),
};
/**
* Initializes socket.io
*
* @evtparam server The server to attach socket.io to.
*/
['__on_install.socketio'] (_, { server }) {
const require = this.require;

View File

@@ -1,7 +1,17 @@
const { AdvancedBase } = require("@heyputer/putility");
/**
* This module initializes a pre-configured web server and socket.io server.
* The main service, WebServerService, emits 'install.routes' and provides
* the server instance to the callback.
*/
class WebModule extends AdvancedBase {
async install (context) {
// === LIBS === //
const useapi = context.get('useapi');
useapi.def('web', require('./lib/__lib__.js'), { assign: true });
// === SERVICES === //
const services = context.get('services');
const SocketioService = require("./SocketioService");