Skip to content

Commit

Permalink
added local server
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Nov 23, 2024
1 parent d33079c commit ce5ed7d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
declare const forge: any;
declare const URLPattern: any;
declare const Deno: any;
48 changes: 48 additions & 0 deletions src/server/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/server/local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* global Deno */
import worker from "./worker.js";
import { serveDir } from "jsr:@std/http/file-server";

const options = {
onListen: () => console.log("Listening on https://localhost"),
cert: await Deno.readTextFile("./static/http-cert.pem"),
key: await Deno.readTextFile("./static/http-key.pem"),
port: 443,
};

Deno.serve(options, async function (req) {
const response = await worker.fetch(req);
return response.status === 404 ? serveDir(req) : response;
});
2 changes: 2 additions & 0 deletions src/utils/create-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function cleanResult(str, year) {
str = str.match(/<main>([^]*)<\/main>/)[1].trim();
str = str.replace(/<article>[^]*<\/article>/, "");
return `<a href="https://adventofcode.com/${year}">[Go Check on Your Calendar]</a> ${str}`;
} else if (str.includes("too recently")) {
return '<input type="submit" value="[Retry (Throttled)]">';
} else {
return str;
}
Expand Down
15 changes: 12 additions & 3 deletions src/utils/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ export const imports = {
...unpkg("es-module-shims"),
};

// export const aocSolverServer = 'https://www.wix.com/_serverless/adventofcode';
// export const aocSolverServer = 'https://aoc.shahar-talmi.workers.dev';
export const aocSolverServer = "https://aoc.deno.dev";
function server() {
if (
typeof location !== "undefined" &&
location.origin === "https://localhost"
) {
return "https://localhost";
} else {
return "https://aoc.deno.dev";
}
}

export const aocSolverServer = server();
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"allowSyntheticDefaultImports": true
},
"exclude": [
"src/server",
"templates"
]
}

0 comments on commit ce5ed7d

Please sign in to comment.