Allow the user to specify hostname to listen on (#138)
This commit is contained in:
@@ -7,6 +7,7 @@ import { SpaceSystem } from "./space_system.ts";
|
||||
import { parseYamlSettings } from "../common/util.ts";
|
||||
|
||||
export type ServerOptions = {
|
||||
hostname: string;
|
||||
port: number;
|
||||
pagesPath: string;
|
||||
dbPath: string;
|
||||
@@ -19,12 +20,14 @@ const staticLastModified = new Date().toUTCString();
|
||||
export class HttpServer {
|
||||
app: Application;
|
||||
systemBoot: SpaceSystem;
|
||||
private hostname: string;
|
||||
private port: number;
|
||||
password?: string;
|
||||
settings: { [key: string]: any } = {};
|
||||
abortController?: AbortController;
|
||||
|
||||
constructor(options: ServerOptions) {
|
||||
this.hostname = options.hostname;
|
||||
this.port = options.port;
|
||||
this.app = new Application(); //{ serverConstructor: FlashServer });
|
||||
this.password = options.password;
|
||||
@@ -125,13 +128,14 @@ export class HttpServer {
|
||||
});
|
||||
|
||||
this.abortController = new AbortController();
|
||||
this.app.listen({ port: this.port, signal: this.abortController.signal })
|
||||
this.app.listen({ hostname: this.hostname, port: this.port, signal: this.abortController.signal })
|
||||
.catch((e: any) => {
|
||||
console.log("Server listen error:", e.message);
|
||||
Deno.exit(1);
|
||||
});
|
||||
const visibleHostname = this.hostname === "0.0.0.0" ? "localhost" : this.hostname;
|
||||
console.log(
|
||||
`Silver Bullet is now running: http://localhost:${this.port}`,
|
||||
`Silver Bullet is now running: http://${visibleHostname}:${this.port}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user