Giter Club home page Giter Club logo

gopher-server's Introduction

gopher-server

npm (tag) npm bundle size (version) npm NPM

A simple gopher server for Node-JS.

Setup

  1. Install using npm install gopher-server

  2. Create the server

    const { GopherServer } = require("gopher-server");
    
    let server = new GopherServer();
  3. Start the server

    server.listen(70);

Creating Content

Content is created through routers. Different routers have different jobs.

Static router

The static router serves content based on files. So, files are layed out like the server will display them.

static
- .gophermap
  content1
  dir1
  - .gophermap
    content2

When accessing a directory, the directory's .gophermap is sent. When the requested resource is a file, the file is sent.

Here is what a .gophermap file may look like.

iHello World	fake	(NULL)	0
0Content 1	/content1	localhost	70

Gopher maps can be confusing to make at first, so the wikipedia page is a good resource. Keep in mind that localhost needs to be changed to your server's hostname. For example, example.com.

app.use(
	new StaticRouter(path.join(__dirname, "static"))
);

Dynamic Router

The dynamic router serves content programmatically. Take for example the dynamic route /test/:id. :id can be replaced by any value. This value can then be used to render and send content to the user.

app.use(
	new DynamicRouter("/test/:id", (request, params) => {
		request.send(`You sent an ID of ${params.id}.`);
	})
);

URL Router

The URL router simply redirects all "URL:" requests to a redirect page. It's more of a utility, and can simply be thrown in and forgotten about.

app.use(new URLRouter());

Example

A full example setup can be found in ./test.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.