error pages and other service pages for serve.zone
Go to file
Philipp Kunz a272df13c8
Some checks failed
Docker (tags) / security (push) Failing after 1s
Docker (tags) / test (push) Has been skipped
Docker (tags) / release (push) Has been skipped
Docker (tags) / metadata (push) Has been skipped
1.0.31
2024-12-26 00:30:12 +01:00
.gitea/workflows initial 2024-12-26 00:29:13 +01:00
.vscode initial 2024-12-26 00:29:13 +01:00
test initial 2024-12-26 00:29:13 +01:00
ts fix(npm): Corrected project description and added keywords in package.json and npmextra.json. 2024-12-26 00:30:12 +01:00
.dockerignore initial 2024-12-26 00:29:13 +01:00
.gitignore initial 2024-12-26 00:29:13 +01:00
changelog.md fix(npm): Corrected project description and added keywords in package.json and npmextra.json. 2024-12-26 00:30:12 +01:00
cli.child.ts initial 2024-12-26 00:29:13 +01:00
cli.js initial 2024-12-26 00:29:13 +01:00
cli.ts.js initial 2024-12-26 00:29:13 +01:00
Dockerfile initial 2024-12-26 00:29:13 +01:00
npmextra.json fix(npm): Corrected project description and added keywords in package.json and npmextra.json. 2024-12-26 00:30:12 +01:00
package.json 1.0.31 2024-12-26 00:30:12 +01:00
pnpm-lock.yaml initial 2024-12-26 00:29:13 +01:00
readme.hints.md initial 2024-12-26 00:29:13 +01:00
readme.md fix(npm): Corrected project description and added keywords in package.json and npmextra.json. 2024-12-26 00:30:12 +01:00
tsconfig.json initial 2024-12-26 00:29:13 +01:00

@losslessone_private/nullresolve

The nullresolve is a robust service designed to manage and handle requests effectively within the servzone architecture. It ensures requests that would normally remain unserved receive appropriate handling and feedback.

Install

To install the @losslessone_private/nullresolve package, it is essential to first set up a proper environment for handling private npm packages due to its private nature. This can be achieved through npm or yarn, which are both suitable JavaScript package managers.

Step-by-Step Installation:

  1. Ensure you are logged into npm with sufficient permissions to access private packages:

    npm login
    

    Authentication is necessary for accessing private modules like @losslessone_private/nullresolve.

  2. Install Using npm:

    npm install @losslessone_private/nullresolve
    

    If you are using a specific registry for your company or project, make sure to specify it in your npm configuration.

  3. Install Using Yarn:

    yarn add @losslessone_private/nullresolve
    

After these steps, the module should be ready for use in your JavaScript or TypeScript project.

Usage

The purpose of nullresolve is pivotal within a network ecosystem, particularly one that interfaces directly with user requests and external resources. Below, a comprehensive guide exists to demonstrate effective usage of this module within applications.

Quick Start Example

Initialization and launching of a nullresolve service can be done succinctly:

// Import the NullResolve class from the package
import { NullResolve } from '@losslessone_private/nullresolve';

// Create an instance of NullResolve
const myNullResolveService = new NullResolve();

// Start the service
myNullResolveService.start().then(() => {
  console.log('NullResolve service is running!');
}).catch((error) => {
  console.error('Error starting NullResolve service:', error);
});

// Stop the service gracefully
process.on('SIGINT', async () => {
  await myNullResolveService.stop();
  console.log('NullResolve service stopped.');
  process.exit(0);
});

Detailed Guide: Handling Requests and Custom Routes

nullresolve can swiftly handle complex request scenarios utilizing its robust framework. Here's a detailed example of setting up custom handler routes that can respond with various HTTP statuses or custom messages based on the request:

import { NullResolve } from '@losslessone_private/nullresolve';

// Initialize the service
const myService = new NullResolve();

// Start the service with custom routes
myService.serviceServer.addCustomRoutes(async (server) => {
  server.addRoute(
    '/error/:code',
    new plugins.typedserver.servertools.Handler('GET', async (req, res) => {
      let message;
      switch (req.params.code) {
        case '404':
          message = 'This resource was not found.';
          break;
        case '500':
          message = 'Internal Server Error. Please try later.';
          break;
        default:
          message = 'An unexpected error occurred.';
      }
      res.status(200).send(`<html><body><h1>${message}</h1></body></html>`);
    })
  );
});

// Activating the service
myService.start().then(() => {
  console.log('Custom route service started.');
}).catch((err) => {
  console.error('Error while starting the service:', err);
});

Integrating Logging and Monitoring

Given the mission-critical nature of services like nullresolve, reliable logging is indispensable to monitor activities and diagnose issues swiftly. This is integrated by default using the smartlog module for robust logging capabilities:

import { logger } from './nullresolve.logging.js';

// Utilize the logger for tracking and problem-solving
logger.info('Service Log: nullresolve service initiated');
logger.warn('Warning Log: Potential issue detected');
logger.error('Error Log: An error occurred in service operation');

Advanced Configuration

For systems requiring specialized setups, nullresolve offers configurability through both code and external configuration objects:

// Customize through code
const config = {
  domain: 'customdomain.com',
  port: 8080,
  routes: [
    {
      method: 'GET',
      path: '/status/check',
      handler: async (req, res) => {
        res.status(200).send('Service is operational.');
      }
    }
  ]
};

myService.configure(config);

// Running the service with a new configuration
myService.start();

Graceful Shutdown and Resource Management

Services such as the one provided by nullresolve must incorporate mechanisms to stop gracefully, allowing them to release resources and finish current tasks before complete termination:

process.on('SIGTERM', async () => {
  logger.info('Service is stopping gracefully.');
  await myService.stop();
  logger.info('Service has been successfully stopped.');
  process.exit(0);
});

Custom Error Handling Strategies

It is often beneficial to ensure that the service reacts gracefully during unexpected shutdowns or errors. Here's an example of implementing a strategy for error handling:

const handleCriticalError = (err: Error) => {
  logger.error(`Critical Error: ${err.message}`);
  process.exit(1);
};

process.on('unhandledRejection', handleCriticalError);
process.on('uncaughtException', handleCriticalError);

By deploying nullresolve strategically within your infrastructure, it can transform how unhandled requests and errors are addressed, providing comprehensive protection and valuable insights into system status and health. This guide should serve to ensure effective deployment, utilization, and management of this sophisticated null service. undefined