-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support passing the port via the command line
- Loading branch information
Showing
13 changed files
with
114 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
{ | ||
"version": "2", | ||
"remote": { | ||
"https://deno.land/[email protected]/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", | ||
"https://deno.land/[email protected]/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", | ||
"https://deno.land/[email protected]/cli/parse_args.ts": "9bea02050b3f302e706871ff87ecfa3ad82cc34249adbe0dcddfaac75bdb48ff", | ||
"https://deno.land/[email protected]/flags/mod.ts": "567a34800a33e701942cb1726dd7e627a76e4681c33ce7346ac85cf90f691a8e", | ||
"https://deno.land/[email protected]/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149", | ||
"https://deno.land/[email protected]/fs/_util.ts": "68508c05d5a02678179a02beabf2b3eac5b16c5a9cbd1c272686d8101bb2679d", | ||
"https://deno.land/[email protected]/fs/copy.ts": "b562e8f482cb8459bb011cbd769769bbdb4f6bc966effd277c06edbdbe41b72e", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { configure, renderFile } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
|
||
const __dirname = new URL(".", import.meta.url).pathname; | ||
|
||
|
@@ -9,10 +10,14 @@ const viewPath = [ | |
]; | ||
|
||
configure({ views: viewPath }); | ||
const flags = parse(Deno.args, { | ||
string: [ "port" ], | ||
default: { port: 80 }, | ||
}); | ||
|
||
const server = Deno.listen({ port: 80 }); | ||
const server = Deno.listen({ port: flags.port }); | ||
|
||
console.log("File server running on http://localhost:80/"); | ||
console.log("File server running on http://localhost:" + flags.port + "/"); | ||
|
||
for await (const conn of server) { | ||
handleHttp(conn).catch(console.error); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
const server = Deno.listen({ port: 80 }); | ||
console.log("File server running on http://localhost:80/index.html"); | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
|
||
const flags = parse(Deno.args, { | ||
string: [ "port" ], | ||
default: { port: 80 }, | ||
}); | ||
|
||
const server = Deno.listen({ port: flags.port }); | ||
console.log("File server running on http://localhost:" + flags.port + "/"); | ||
|
||
const __dirname = new URL(".", import.meta.url).pathname; | ||
|
||
for await (const conn of server) { | ||
|
@@ -9,7 +17,7 @@ for await (const conn of server) { | |
async function handleHttp(conn: Deno.Conn) { | ||
const httpConn = Deno.serveHttp(conn); | ||
for await (const requestEvent of httpConn) { | ||
|
||
const url = new URL(requestEvent.request.url); | ||
const filepath = decodeURIComponent(url.pathname); | ||
|
||
|
@@ -27,4 +35,4 @@ async function handleHttp(conn: Deno.Conn) { | |
const response = new Response(readableStream); | ||
await requestEvent.respondWith(response); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
const server = Deno.listen({ port: 80 }); | ||
console.log("File server running on http://localhost:80/index.html"); | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
|
||
const flags = parse(Deno.args, { | ||
string: [ "port" ], | ||
default: { port: 80 }, | ||
}); | ||
|
||
const server = Deno.listen({ port: flags.port }); | ||
console.log("File server running on http://localhost:" + flags.port + "/"); | ||
|
||
const __dirname = new URL(".", import.meta.url).pathname; | ||
|
||
for await (const conn of server) { | ||
|
@@ -9,7 +17,7 @@ for await (const conn of server) { | |
async function handleHttp(conn: Deno.Conn) { | ||
const httpConn = Deno.serveHttp(conn); | ||
for await (const requestEvent of httpConn) { | ||
|
||
const url = new URL(requestEvent.request.url); | ||
let filepath = decodeURIComponent(url.pathname); | ||
if(filepath === "/") { | ||
|
@@ -30,4 +38,4 @@ async function handleHttp(conn: Deno.Conn) { | |
const response = new Response(readableStream); | ||
await requestEvent.respondWith(response); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
const server = Deno.listen({ port: 80 }); | ||
console.log("File server running on http://localhost:80/index.html"); | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
|
||
const flags = parse(Deno.args, { | ||
string: [ "port" ], | ||
default: { port: 80 }, | ||
}); | ||
|
||
const server = Deno.listen({ port: flags.port }); | ||
console.log("File server running on http://localhost:" + flags.port + "/"); | ||
|
||
const __dirname = new URL(".", import.meta.url).pathname; | ||
|
||
for await (const conn of server) { | ||
|
@@ -9,7 +17,7 @@ for await (const conn of server) { | |
async function handleHttp(conn: Deno.Conn) { | ||
const httpConn = Deno.serveHttp(conn); | ||
for await (const requestEvent of httpConn) { | ||
|
||
const url = new URL(requestEvent.request.url); | ||
let filepath = decodeURIComponent(url.pathname); | ||
if(filepath === "/") { | ||
|
@@ -32,4 +40,4 @@ async function handleHttp(conn: Deno.Conn) { | |
const response = new Response(readableStream); | ||
await requestEvent.respondWith(response); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { configure, renderFile } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
|
||
const __dirname = new URL(".", import.meta.url).pathname; | ||
|
||
|
@@ -10,9 +11,13 @@ const viewPath = [ | |
|
||
configure({ views: viewPath }); | ||
|
||
const server = Deno.listen({ port: 80 }); | ||
const flags = parse(Deno.args, { | ||
string: [ "port" ], | ||
default: { port: 80 }, | ||
}); | ||
|
||
console.log("File server running on http://localhost:80/"); | ||
const server = Deno.listen({ port: flags.port }); | ||
console.log("File server running on http://localhost:" + flags.port + "/"); | ||
|
||
for await (const conn of server) { | ||
handleHttp(conn).catch(console.error); | ||
|