v1.0.0 and an NPM module
* Fix a bug with requests without a trailing slash
This commit is contained in:
parent
69e49e7f84
commit
e53fb7a8fe
|
@ -103,7 +103,8 @@ export default class GeminiServer {
|
|||
}
|
||||
|
||||
handleRequest(url, socket) {
|
||||
const urlPath = url.pathname;
|
||||
//In the case of "gemini://example.com" url.pathname is "", which is a problem when we later .resolve
|
||||
const urlPath = url.pathname || "/";
|
||||
for (const p of this.pathRegistry) {
|
||||
//TODO: Wildcard hostnames
|
||||
if (wildHostMatches(p.hostname, socket.servername)) {
|
||||
|
|
35
main.js
35
main.js
|
@ -1,35 +1,4 @@
|
|||
import tls from "tls";
|
||||
import fs from "fs";
|
||||
|
||||
import GeminiServer from "./GeminiServer.js"
|
||||
import StaticHandler from "./handlers/static.js"
|
||||
|
||||
const options = {
|
||||
//cert: fs.readFileSync("public-cert.pem"),
|
||||
//key: fs.readFileSync("private-key.pem"),
|
||||
SNICallback: function (servername, callback) {
|
||||
console.log(servername);
|
||||
if (servername === "localhost") {
|
||||
callback(null, tls.createSecureContext({
|
||||
cert: fs.readFileSync("public-cert.pem"),
|
||||
key: fs.readFileSync("private-key.pem"),
|
||||
}));
|
||||
}else {
|
||||
callback(null, tls.createSecureContext({
|
||||
cert: fs.readFileSync("mac-gamma-pub-cert.pem"),
|
||||
key: fs.readFileSync("mac-gamma-key.pem")
|
||||
}))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const server = tls.createServer(options);
|
||||
server.on("secureConnection", socket => {
|
||||
socket.setEncoding("utf8");
|
||||
socket.write("20 text/gemini\r\n");
|
||||
socket.write("Hello, world!\r\n");
|
||||
socket.write(`You're connecting from ${socket.servername}`)
|
||||
socket.end();
|
||||
});
|
||||
server.listen(1965);
|
||||
|
||||
export { GeminiServer }
|
||||
export { GeminiServer, StaticHandler };
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"name": "flying-theater",
|
||||
"version": "v0.1.0",
|
||||
"name": "astronomical-theater",
|
||||
"version": "v1.0.0",
|
||||
"author": "Matthias",
|
||||
"license": "UNLICENSED",
|
||||
"license": "CC0-1.0",
|
||||
"type": "module",
|
||||
"entry": "main.js",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "node main.js"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue