Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
spalberg committed Dec 6, 2024
1 parent 17d81e3 commit be2f6f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and explore the code. Happy coding and may your algorithms be ever efficient!
## CLI

You don't have to check out this repository to test my code against your inputs!
Simply run the published cli via JSR.
Simply run the published cli via [JSR](https://jsr.io/).

Usage:

Expand All @@ -32,20 +32,37 @@ cat ./inputs/2.txt | deno run jsr:@aoc/2024 -d 2
> version is out of date. Simply run `deno run -A jsr:@aoc/2024 update` to
> update to the latest version.
# SaaS (Solutions as a Service)
## SaaS (Solutions as a Service)

You don't have deno installed and just want to get some solutions for your
puzzle inputs?\
SaaS is the future and here to save you!
_You don't have deno installed and just want to get some solutions for your
puzzle inputs?_\
_SaaS_ is the future and here to save you!

// TOOD ...
All solutions are available as an API, powered by
[Deno Deploy](https://deno.com/deploy).

```pswh
irm -method "post" https://aoc-2024.palberg.de/days/2 -Body (gc -raw ./inputs/2.txt)
```
### _Almost OpenAPI_ ™ Spec:

Use one of these base urls:
[`https://aoc-2024.palberg.de`](https://aoc-2024.palberg.de/info) or
[`https://aoc-2024.deno.dev`](https://aoc-2024.deno.dev/info).

- `POST /days/:number`: send your raw input as body to get the results
- `GET /info`: get some nice infos
- `GET /days`: see what days are available

### Examples

// TODO curl not working yet...
If you have access to `curl` you can adopt the following example for your
usecase:

```bash
curl -X POST -d @./inputs/2.txt https://aoc-2024.palberg.de/days/2
curl -X POST --data-binary @./inputs/1.txt https://aoc-2024.palberg.de/days/1
```

If you are more of a power (_shell_) user the following example might be a
better starting point for you:

```pswh
irm -method "post" https://aoc-2024.palberg.de/days/2 -Body (gc -raw ./inputs/2.txt)
```
2 changes: 1 addition & 1 deletion saas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
async fetch(req) {
const url = new URL(req.url);
url.pathname = url.pathname.replace(/\/$/, "");
console.log(`Request for ${url.pathname}`);

if (url.pathname === "/info") {
return new Response(
Expand Down Expand Up @@ -49,7 +50,6 @@ export default {
}

const num = parseInt(match.pathname.groups.num ?? "", 10);
console.log(`Providing solution for day ${num}`);
const day = days.get(num);
if (day == null) {
return new Response(null, { status: 404 });
Expand Down

0 comments on commit be2f6f0

Please sign in to comment.