@serverful/core

The core Serverful library

Usage no npm install needed!

<script type="module">
  import serverfulCore from 'https://cdn.skypack.dev/@serverful/core';
</script>

README

Serverful

An interface for creating HTTP servers, together with powerful features and extensions.

Features

  • Effective and performant HTTP interface.
  • Shortcut behaviour, like gateways and redirects.
  • Optional integration of EJS templates.
  • Native cookie parsing.
  • Rich extension management.

Links

Extensions

Installation

npm install @serverful/core

const Serverful = require("@serverful/core");
// ...

Usage

Creation of a Serverful instance.

const MyServer = new Serverful(Port);

Registration of Serverful extensions.

Serverful.Extension(ServerfulExtension);

Gateways

// /**
MyServer.Incoming(Handler);

// /public/**
MyServer.Gateway("public", Handler);

// /api/**
MyServer.Gateway("api", Handler);

Requests

// Handler
// Redirect the user relatively or absolute.
Packet.Request.Redirect("/dashboard/index");
Packet.Request.Redirect("https://duckduckgo.com/");

// Render an EJS template.
Packet.Request.Render(EJSTemplate, Document)
.then(() => Packet.Request.End(200))
.catch(() => Packet.Request.End(500));

// JSON.
Packet.Request.JSON(Document);

This module is licensed under Apache 2.0.