Jump to content
Returning Members: Password Reset Required ×

@nullgato/transgress - Overcomplicated, opinionated web server framework for Bun


nullgato

Recommended Posts

ℹ Overview

This is my own web development framework I wrote for a couple of my projects I'm working on. It includes some helper tools that allow you to get started developing for the Bun platform (similar to Node JS) in TypeScript with easy to read logging, easy routing, and the repository contains sample code to get you off and running. It also includes some potentially useful stuff for websockets since that's required for one of my projects as well like a base packet structure that includes (de)serialization methods to make using it easy.

 

My own favorite feature is the string interpolation I've added where you can create an html file with {{ variable }} as the text and you can use the included helper class to load the file with the object containing your variables to be replaced with. It's a small and easy thing to do, but gosh does it go a long way.

 

Available on npm under the package @nullgato/transgress

 

🧩 Features

  • An alright routing system
  • Probably okay performance
  • A middleware system
  • Support for websockets (not really a flex, I'm running out of yays)
  • Support for HTML pages and {{variable}} within them
  • A template for websocket packets via abstract class BasePacket
  • Uhhhhh

 

💻 Example Usage

import { Logger, Middleware } from '@nullgato/transgress/core'
import { transgress } from '@nullgato/transgress'
import type { ILogger, ILogObject, ITransgressOptions } from '@nullgato/transgress/interfaces'
import { OLogLevel, type RouterResponse } from '@nullgato/transgress/types'

// you can write your own ILogger, but one is provided for you
const logger = new Logger(OLogLevel.Info)

// same with the IMiddleware interface
const middleware = new Middleware(logger)

middleware.register({
    name: 'middleware',
    callback: async (logger: ILogger, req: Request): RouterResponse => {
        return new Response('hewwo', { status: 200 })
    },
    log: (logger: ILogger, data: string | ILogObject): ILogger => {
        return logger
    },
})

const options: ITransgressOptions = {
    development: true,
    // the errorHandler is optional
    errorHandler: (error: Error) => {
        return new Response('rip', { status: 200 })
    },
    middleware,
    port: 12000,
}

const server = transgress(options)

// Server is now listening for connections

 

🔗 Source on GitHub

https://github.com/nullgato/transgress

Link to comment
Share on other sites

  • 2 weeks later...
On 9/9/2024 at 1:01 AM, Spirited said:

I'm curious, which projects do you do that require web sockets? Also, nice use of the board's new emoji support. 👍

Sorry for the long wait on this! I only have one project at the moment, but I'm working on a music player widget to display on my streams that can be reactive to input sent from my stream deck. The widget and server have a subscribe/publish pattern, and the communication works like this:
 

Widget <-> Webserver

The websocket allows for efficient data flow keeping media player data synchronized such as current song, estimated seek position, song attributes, album art, commands such as play/pause/previous/next, far faster than API requests. The webserver's role in this relationship is to communicate desired changes to the widget where the widget will then send a response as to whether that desired change was successful or not.

 

Stream Deck <-> Webserver

The Stream Deck interacts via API to send/process my desired commands which will have a success/failure result depending on the decision made on the backend. For example if I ask for a specific song but the song for some reason isn't available, this will not be forwarded to the Widget and the Stream Deck will be given a failure response to display to me. Likewise for the opposite, if the song exists and the Widget & Player were able to have a successful interaction, I'll be given a successful response and the Stream Deck will report that to me visually as well.

 

Desired commands because I like to keep realistic expectations that I'm sure I'll have undesired outcomes at times. 😂

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...