Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

oeath/bare-server-node

Open more actions menu
 
 

Repository files navigation

TOMP Bare Server

This repository implements the TompHTTP bare server. See the specification here.

Usage

We provide a command-line interface for creating a server.

For more features, specify the --help option when running the CLI.

Quickstart

  1. Install Bare Server Node globally
npm install --global @tomphttp/bare-server-node
  1. Start the server
npx bare-server-node

Optionally start the server localhost:8080

npx bare-server-node --port 8080 --host localhost

Programically create a bare server

import createBareServer from '@tomphttp/bare-server-node';
import { createServer as createHttpServer } from 'http';

const httpServer = createHttpServer();

const bareServer = createBareServer('/', {
	logErrors: false,
	localAddress: undefined,
	maintainer: {
		email: 'tomphttp@sys32.dev',
		website: 'https://github.com/tomphttp/',
	},
});

httpServer.on('request', (req, res) => {
	if (bareServer.shouldRoute(req)) {
		bareServer.routeRequest(req, res);
	} else {
		res.writeHead(400);
		res.send('Not found.');
	}
});

httpServer.on('upgrade', (req, socket, head) => {
	if (bareServer.shouldRoute(req)) {
		bareServer.routeUpgrade(req, socket, head);
	} else {
		socket.end();
	}
});

httpServer.on('listening', () => {
	console.log('HTTP server listening');
});

httpServer.listen({
	port: 8080,
});

About

The TOMP bare server, written in NodeJS.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 91.7%
  • JavaScript 8.3%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.