Skip to content

Commit 18acbe4

Browse files
authored
Merge pull request #28 from googleanalytics/portsfix
[fix] address issues with starting deno from each directory
2 parents ca8ff8a + d4636f5 commit 18acbe4

File tree

8 files changed

+25
-61
lines changed

8 files changed

+25
-61
lines changed

src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import * as path from "https://deno.land/[email protected]/path/mod.ts";
22
import { Eta } from "https://deno.land/x/[email protected]/src/index.ts";
33
import { parseArgs } from "jsr:@std/cli/parse-args";
44

5-
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
6-
7-
const viewpath = Deno.cwd() + "/public/";
8-
const eta = new Eta({ views: viewpath, cache: true });
5+
const __dirname = new URL(".", import.meta.url).pathname;
6+
const eta = new Eta({ views: path.join(__dirname, 'public'), cache: true });
97

108
const flags = parseArgs(Deno.args, {
119
string: ["port"],
12-
default: { port: "3000" },
10+
default: { port: "80" },
1311
});
1412

1513
async function handler(request: Request) {

tutorials/1-initial-setup/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ async function handleHttp(conn: Deno.Conn) {
1919
for await (const requestEvent of httpConn) {
2020

2121
const url = new URL(requestEvent.request.url);
22-
const filepath = decodeURIComponent(url.pathname);
22+
let filepath = decodeURIComponent(url.pathname);
23+
if(filepath === "/") {
24+
filepath = "/index.html"
25+
}
2326

2427
let file;
2528
try {

tutorials/1-initial-setup/src/public/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
<li class="nav-item">
3939
<a class="nav-link active" aria-current="page" href="/index.html">Home</a>
4040
</li>
41-
<li class="nav-item">
42-
<a class="nav-link" href="/about.html">About</a>
43-
</li>
4441
</ul>
4542
</div>
4643
</div>

tutorials/2-events/src/public/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
<li class="nav-item">
4040
<a class="nav-link active" aria-current="page" href="/index.html">Home</a>
4141
</li>
42-
<li class="nav-item">
43-
<a class="nav-link" href="/about.html">About</a>
44-
</li>
4542
</ul>
4643
</div>
4744
</div>

tutorials/3-custom-events/index.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

tutorials/3-custom-events/src/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
const server = Deno.listen({ port: 80 });
2-
console.log("File server running on http://localhost:80/index.html");
1+
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
2+
3+
const flags = parse(Deno.args, {
4+
string: [ "port" ],
5+
default: { port: 80 },
6+
});
7+
8+
const server = Deno.listen({ port: flags.port });
9+
console.log("File server running on http://localhost:" + flags.port + "/");
10+
311
const __dirname = new URL(".", import.meta.url).pathname;
412

513
for await (const conn of server) {
@@ -9,7 +17,7 @@ for await (const conn of server) {
917
async function handleHttp(conn: Deno.Conn) {
1018
const httpConn = Deno.serveHttp(conn);
1119
for await (const requestEvent of httpConn) {
12-
20+
1321
const url = new URL(requestEvent.request.url);
1422
let filepath = decodeURIComponent(url.pathname);
1523
if(filepath === "/") {
@@ -32,4 +40,4 @@ async function handleHttp(conn: Deno.Conn) {
3240
const response = new Response(readableStream);
3341
await requestEvent.respondWith(response);
3442
}
35-
}
43+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"tasks": {
3-
"start": "deno run -A --watch=public/ index.ts"
3+
"start": "deno run --allow-net --allow-read --watch=public/ index.ts"
44
}
55
}

tutorials/4-consent-mode/src/deno.lock

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)