add listening info on start

This commit is contained in:
HorizonCode 2023-05-10 15:00:17 +02:00
parent c6c739394f
commit 469a83c8e7

View File

@ -30,6 +30,12 @@ export class HTTPServer {
hostname: options.host, hostname: options.host,
}); });
console.log(
`Listening on ${
options.host ? options.host : "http://localhost"
}:${options.port} !`,
);
if (options.staticLocalDir && options.staticServePath) { if (options.staticLocalDir && options.staticServePath) {
this.staticLocalDir = options.staticLocalDir; this.staticLocalDir = options.staticLocalDir;
this.staticServePath = options.staticServePath; this.staticServePath = options.staticServePath;
@ -42,14 +48,12 @@ export class HTTPServer {
const filepath = decodeURIComponent(url.pathname); const filepath = decodeURIComponent(url.pathname);
if (this.staticServePath && filepath.startsWith(this.staticServePath)) { if (this.staticServePath && filepath.startsWith(this.staticServePath)) {
console.log(filepath, this.staticServePath);
const fileDir = filepath.split("/").slice(2).join("/"); const fileDir = filepath.split("/").slice(2).join("/");
const pathLoc = path.join( const pathLoc = path.join(
Deno.cwd(), Deno.cwd(),
this.staticLocalDir as string, this.staticLocalDir as string,
fileDir, fileDir,
); );
console.log(pathLoc);
let file; let file;
try { try {
file = await Deno.open(pathLoc, { read: true }); file = await Deno.open(pathLoc, { read: true });