A gopher server written in javascript.
npm install --save gopherserver.js
-
options
<Object>
See net.createServer([options][, connectionListener]) -
connectionListener
<Function>
Automatically set as a listener for therequest
event. - Returns:
<net.Server>
-
<net.Socket>
The connection object
Emitted when a new request is made.
A string of requested URL path. Could also a CCSO Nameserver query if this url begin with query
.
socket.url // "/"
socket.url // ""
socket.url // "/pathname/"
socket.url // "query Hello world"
A full-text search query string. Only available when client is requesting with mode 7
.
socket.query // Lorem ipsum dolor sit amet
socket.query // What is NodeJS?
socket.query // Hello world
A function to send a rendered gophermap to client. Can only be called once.
let map = `!My Gopher server
Hello world, This is my gopher server!`;
socket.send(map);
A function to send a rendered menu entity to client. Can only be called once.
socket.menu({
INFO: "1Menu\tlocalhost\t2000",
ADMIN: "\n Admin: Me"
}, -2);
// +-2
// +INFO: 1Menu localhost 2000
// +ADMIN:
// Admin: Me
A function that used by socket.send(map)
function to render a string into gophermap.
gophermap:
!My Gopher server
Hello world, This is my gopher server!
index.js:
const gopherserver = require("gopherserver.js");
const fs = require("fs");
let file = fs.readFileSync("gophermap", "utf8");
gopherserver.render(file);
// iMy Gopher Server TITLE null.host 1
// i null.host 1
// iHello world, This is my gopher server! null.host 1
A function that used by socket.menu(menu)
to render a string into gopher menu entity.
const gopherServer = require("gopherserver.js");
const server = gopherServer();
server.on('request', soc => {
if (!soc.url && soc.query === "$") { // Client is requesting menu entity
return soc.menu({
INFO: "1Main Menu\tlocalhost\t2000",
ADMIN: "\n Admin: Me"
}, -2);
}
soc.send("Hello world!");
});
server.on('error', console.error);
server.listen(2000);