Skip to content

Commit

Permalink
chore: tweak implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhrznr committed Jul 13, 2023
1 parent 835e0a1 commit 5c0601c
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 124 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Deploy
on: [push]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

steps:
- name: Clone repository
uses: actions/checkout@v3

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Build site
run: deno run -A ./build.ts

- name: Upload to Deno Deploy
uses: denoland/deployctl@v1
with:
project: ultra-deno-kv-oauth-demo
entrypoint: server.js
root: .ultra
import-map: importMap.server.json
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

Demo of [Deno KV OAuth](https://deno.land/x/deno_kv_oauth) working in Ultra.

Your new Ultra project is ready to go. You can follow the Ultra docs here: https://ultrajs.dev/
Your new Ultra project is ready to go. You can follow the Ultra docs here:
https://ultrajs.dev/

### Usage

Make sure to install Deno: https://deno.land/manual/getting_started/installation

Then start the project:
Then start the project in dev mode:
This will watch the project directory and restart as necessary.

```
deno task start
deno task dev
```

This will watch the project directory and restart as necessary.
Or start the project in production mode:

```
deno task build && cd .ultra && deno task start
```
18 changes: 18 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createBuilder } from "ultra/build.ts";

const builder = createBuilder({
browserEntrypoint: import.meta.resolve("./client.tsx"),
serverEntrypoint: import.meta.resolve("./server.tsx"),
});

builder.ignore([
"./README.md",
"./importMap.json",
"./.git/**",
"./.vscode/**",
"./.github/**",
"./.gitignore",
]);

// deno-lint-ignore no-unused-vars
const result = await builder.build();
8 changes: 8 additions & 0 deletions client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import hydrate from "ultra/hydrate.js";
import App from "./src/app.tsx";

function ClientApp() {
return <App />;
}

hydrate(document, <ClientApp />);
19 changes: 13 additions & 6 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{
"tasks": {
"dev": "deno run -A --no-check --unstable --watch ./server.tsx",
"test": "deno test --allow-all",
"build": "deno run -A ./build.ts",
"start": "ULTRA_MODE=production deno run -A --unstable --no-remote ./server.js"
},
"compilerOptions": {
"jsx": "react-jsxdev",
"jsxImportSource": "react",
"lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"]
},
"fmt": {},
"lint": {},
"importMap": "./importMap.json",
"tasks": {
"start": "deno run -A --no-check --unstable --watch ./main.tsx"
}
"fmt": {
"files": { "exclude": [".ultra"] }
},
"lint": {
"files": { "exclude": [".ultra"] }
},
"importMap": "./importMap.json"
}
226 changes: 120 additions & 106 deletions deno.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions importMap.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"imports": {
"react": "https://esm.sh/[email protected]",
"react": "https://esm.sh/[email protected]?dev",
"react/": "https://esm.sh/[email protected]/",
"react-dom": "https://esm.sh/[email protected]",
"react-dom/server": "https://esm.sh/[email protected]/server",
"react-dom/server": "https://esm.sh/[email protected]/server?dev",
"react-dom/client": "https://esm.sh/[email protected]/client?dev",

"kv_oauth": "https://deno.land/x/[email protected]/mod.ts",
"std/": "https://deno.land/[email protected]/",
"ultra/": "https://deno.land/x/[email protected]/"
"ultra/": "https://deno.land/x/[email protected]/",
"std/": "https://deno.land/[email protected]/"
}
}
10 changes: 7 additions & 3 deletions main.tsx → server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
signOut,
} from "kv_oauth";

import App from "./app.tsx";
import App from "./src/app.tsx";

loadSync({ export: true });

Expand All @@ -19,7 +19,11 @@ const server = await createServer({
importMapPath: import.meta.resolve("./importMap.json"),
});

console.log(Deno.version)
function ServerApp({ accessToken, isSignedIn }: {
accessToken: string | null;
isSignedIn: boolean}) {
return <App {...{ accessToken, isSignedIn }} />;
}

server
.get("/", async (ctx) => {
Expand All @@ -29,7 +33,7 @@ server
? await getSessionAccessToken(oauth2Client, sessionId)
: null;
const result = await server.render(
<App {...{ accessToken, isSignedIn }} />,
<ServerApp {...{ accessToken, isSignedIn }} />,
);

return ctx.body(result, 200, {
Expand Down
2 changes: 1 addition & 1 deletion app.tsx → src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ export default function App(
</body>
</html>
);
}
}

0 comments on commit 5c0601c

Please sign in to comment.