Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
clean: true
persist-credentials: false
set-safe-directory: true
fetch-depth: 1
- name: 🐦 Set up Flutter
id: flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
Expand Down Expand Up @@ -109,6 +110,7 @@ jobs:
clean: true
persist-credentials: false
set-safe-directory: true
fetch-depth: 1
- name: 🐦 Set up Flutter
id: flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
Expand Down Expand Up @@ -153,7 +155,7 @@ jobs:
if: ${{ matrix.target == 'web' }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: app-${{ matrix.target }}-build
name: build-${{ matrix.target }}
path: "./packages/app/build/"
if-no-files-found: error

Expand All @@ -171,6 +173,7 @@ jobs:
clean: true
persist-credentials: false
set-safe-directory: true
fetch-depth: 1
- name: 🐦 Set up Flutter
id: flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
Expand Down Expand Up @@ -217,6 +220,7 @@ jobs:
clean: true
persist-credentials: false
set-safe-directory: true
fetch-depth: 1
- name: 🐦 Set up Flutter
id: flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
Expand Down Expand Up @@ -273,6 +277,7 @@ jobs:
clean: true
persist-credentials: false
set-safe-directory: true
fetch-depth: 1
- name: 🐦 Set up Flutter
id: flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
Expand All @@ -285,21 +290,61 @@ jobs:
- name: ✨ Verify formatting
run: dart format . --output=none --set-exit-if-changed

deploy:
name: Deploy
needs: ["build"]
runs-on: ubuntu-latest
timeout-minutes: 2

permissions:
id-token: write # Needed to authenticate with Deno Deploy.
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true

steps:
- name: 📚 Git checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
clean: true
persist-credentials: false
set-safe-directory: true
fetch-depth: 1
sparse-checkout: packages/server
- name: ⚙️ Download build
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
name: build-web
path: "./packages/server/static"
- name: 🔧 Deploy
uses: denoland/deployctl@612f83df2b874c6908d68de5cf3f36a6538fa8f7 # 1.12.0
with:
project: "harvest-hub"
entrypoint: ./src/server.ts
root: packages/server
include: |
src/
static/
deno.json
deno.lock

spell-check:
name: Check Spelling
needs: []
runs-on: ubuntu-latest

steps:
- name: 📚 Git Checkout
- name: 📚 Git checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive
clean: true
persist-credentials: false
set-safe-directory: true
fetch-depth: 1

- name: 🪄 Spell Check
- name: 🪄 Spell check
uses: streetsidesoftware/cspell-action@934c74da3775ac844ec89503f666f67efb427fed # v6.8.1
with:
files: |
Expand Down Expand Up @@ -331,14 +376,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: 📚 Git Checkout
- name: 📚 Git checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive
clean: true
persist-credentials: false
set-safe-directory: true
- name: 🕵️ Markdown linting
fetch-depth: 1
- name: 🕵️ Lint Markdown
uses: DavidAnson/markdownlint-cli2-action@db43aef879112c3119a410d69f66701e0d530809 # v17.0.0
id: markdownlint
with:
Expand Down
22 changes: 22 additions & 0 deletions packages/server/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.11",
"@std/http": "jsr:@std/http@^1.0.13",
"@std/path": "jsr:@std/path@^1.0.8"
},
"compilerOptions": {
"strict": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitOverride": true,
"exactOptionalPropertyTypes": true,
"noUncheckedIndexedAccess": true,
"noPropertyAccessFromIndexSignature": true,
"noUnusedLocals": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"noUnusedParameters": true,
"useUnknownInCatchVariables": true,
"verbatimModuleSyntax": true
}
}
71 changes: 71 additions & 0 deletions packages/server/deno.lock

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

55 changes: 55 additions & 0 deletions packages/server/src/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { assertEquals, assertStringIncludes } from "@std/assert";
import { join } from "@std/path";
import { respond } from "./server.ts";

async function populateTempDir(
files: readonly { name: string; content: string }[]
): Promise<string> {
const encoder = new TextEncoder();
const tempDirPath = await Deno.makeTempDir();

const promises = files.map(async ({ name, content }) => {
await Deno.writeFile(join(tempDirPath, name), encoder.encode(content));
});

await Promise.all(promises);

return tempDirPath;
}

Deno.test(
"serveDir should return the correct response for an html file",
async () => {
const tempDirPath = await populateTempDir([
{ name: "index.html", content: "" },
{ name: "index.pck", content: "" },
{ name: "index.wasm", content: "" },
]);

const req = new Request("http://localhost");
const res = await respond(req, tempDirPath);
await res.body?.cancel();

assertEquals(res.status, 200);
assertStringIncludes(res.headers.get("Content-Type") ?? "", "text/html");
}
);

Deno.test(
"serveDir should return the correct response for a wasm file",
async () => {
const tempDirPath = await populateTempDir([
{ name: "index.wasm", content: "" },
]);

const req = new Request("http://localhost/index.wasm");
const res = await respond(req, tempDirPath);
await res.body?.cancel();

assertEquals(res.status, 200);
assertStringIncludes(
res.headers.get("Content-Type") ?? "",
"application/wasm"
);
}
);
19 changes: 19 additions & 0 deletions packages/server/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { serveDir } from "@std/http";

export async function respond(req: Request, dir = "static"): Promise<Response> {
const res = await serveDir(req, {
fsRoot: dir,
enableCors: true,
});

res.headers.set("Cross-Origin-Opener-Policy", "same-origin");
res.headers.set("Cross-Origin-Embedder-Policy", " require-corp");

return res;
}

export default {
fetch: async (req: Request): Promise<Response> => {
return await respond(req);
},
} satisfies Deno.ServeDefaultExport;
Loading