Skip to content

Commit efbc034

Browse files
committed
serve astro assets directly through nginx and optimize script loading order
1 parent 76bc86a commit efbc034

8 files changed

Lines changed: 98 additions & 81 deletions

File tree

astro-app/astro.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import node from "@astrojs/node";
99
export default defineConfig({
1010
base: "/xnode-auth",
1111

12+
build: {
13+
client: "./xnode-auth",
14+
},
15+
1216
vite: {
1317
plugins: [tailwindcss()],
1418
ssr: {
Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
<appkit-button balance="hide"></appkit-button>
22
<script>
3-
import "../scripts/appkit";
3+
import { createAppKit } from "@reown/appkit";
4+
import { mainnet } from "@reown/appkit/networks";
5+
import { appkitStore } from "../store/appkit";
6+
import { isAddress } from "viem";
7+
import { projectId, wagmiAdapter } from "../scripts/wagmi";
8+
9+
const metadata = {
10+
name: "Xnode Auth",
11+
description: "Web3 authenticator and login dashboard.",
12+
url: "https://auth.xnode.openmesh.network",
13+
icons: ["https://auth.xnode.openmesh.network/favicon.svg"],
14+
};
15+
16+
const modal = createAppKit({
17+
adapters: [wagmiAdapter],
18+
networks: [mainnet],
19+
metadata,
20+
projectId,
21+
defaultAccountTypes: {
22+
eip155: "eoa",
23+
},
24+
// social features only work with projects that have whitelisted domains, which cannot be done for the default project id, as it would prevent it to be used on all websites
25+
features: {
26+
...(projectId === "6afdeb3a0496b33061a69538819a9a7e"
27+
? { email: false, socials: false }
28+
: {}),
29+
analytics: false,
30+
swaps: false,
31+
onramp: false,
32+
},
33+
});
34+
35+
modal.subscribeAccount((state) => {
36+
const address = state.address;
37+
if (address === undefined || isAddress(address)) {
38+
appkitStore.account.set(address);
39+
} else {
40+
console.warn(`Invalid appkit address ${address}`);
41+
}
42+
});
443
</script>

astro-app/src/components/Login.astro

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,17 @@ import Connect from "../components/Connect.astro";
5151
>
5252
</div>
5353
<script>
54-
import { wagmiAdapter } from "../scripts/appkit";
54+
import sdk from "@farcaster/miniapp-sdk";
55+
sdk.actions.ready();
56+
</script>
57+
<script>
58+
import { wagmiAdapter } from "../scripts/wagmi";
5559
import { getMessage } from "../lib/message";
5660
import { toXnodeAddress } from "../lib/xnode-address";
57-
import { appkitStore } from "../store/appkit";
5861
import { signMessage } from "@wagmi/core";
59-
60-
function setRedirect(redirect: string) {
61-
const node = document.getElementById("redirect");
62-
if (node) {
63-
node.textContent = redirect;
64-
}
65-
}
66-
67-
function setError(error: string) {
68-
const node = document.getElementById("error");
69-
if (node) {
70-
node.style.display = error ? "flex" : "none";
71-
node.textContent = error;
72-
}
73-
}
62+
import { appkitStore } from "../store/appkit";
63+
import { setError } from "../scripts/reactive";
64+
import { redirect } from "../scripts/params";
7465

7566
let signingState = false;
7667
function setSigning(signing: boolean) {
@@ -98,14 +89,6 @@ import Connect from "../components/Connect.astro";
9889
}
9990
}
10091

101-
const urlParams = new URLSearchParams(window.location.search);
102-
103-
const redirect = urlParams.get("redirect") ?? window.location.origin;
104-
setRedirect(redirect);
105-
106-
const rejected = urlParams.get("rejected");
107-
setError(rejected ?? "");
108-
10992
appkitStore.account.subscribe((account) => {
11093
if (!account) {
11194
signingState = false;
@@ -166,6 +149,9 @@ import Connect from "../components/Connect.astro";
166149
});
167150
</script>
168151
<script>
169-
import sdk from "@farcaster/miniapp-sdk";
170-
sdk.actions.ready();
152+
import { setRedirect, setError } from "../scripts/reactive";
153+
import { redirect, rejected } from "../scripts/params";
154+
155+
setRedirect(redirect);
156+
setError(rejected ?? "");
171157
</script>

astro-app/src/scripts/appkit.ts

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

astro-app/src/scripts/params.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const urlParams = new URLSearchParams(window.location.search);
2+
export const redirect = urlParams.get("redirect") ?? window.location.origin;
3+
export const rejected = urlParams.get("rejected");

astro-app/src/scripts/reactive.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function setRedirect(redirect: string) {
2+
const node = document.getElementById("redirect");
3+
if (node) {
4+
node.textContent = redirect;
5+
}
6+
}
7+
8+
export function setError(error: string) {
9+
const node = document.getElementById("error");
10+
if (node) {
11+
node.style.display = error ? "flex" : "none";
12+
node.textContent = error;
13+
}
14+
}

astro-app/src/scripts/wagmi.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mainnet } from "@reown/appkit/networks";
2+
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
3+
import { config } from "../lib/config";
4+
import farcasterMiniApp from "@farcaster/miniapp-wagmi-connector";
5+
6+
export const projectId = config.eth.projectid;
7+
8+
export const networks = [mainnet];
9+
10+
export const wagmiAdapter = new WagmiAdapter({
11+
projectId,
12+
networks,
13+
connectors: [farcasterMiniApp()],
14+
});

nix/nixos-module.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,16 @@ in
332332
))
333333
{
334334
"${cfg.nginxConfig.subpath}" = {
335-
proxyPass = "http://127.0.0.1:${builtins.toString cfg.port}";
335+
root = "${xnode-auth}/share";
336+
};
337+
"${cfg.nginxConfig.subpath}/_astro" = {
338+
root = "${xnode-auth}/share";
339+
extraConfig = ''
340+
add_header Cache-Control "public, max-age=31536000, immutable";
341+
'';
342+
};
343+
"${cfg.nginxConfig.subpath}/api" = {
344+
proxyPass = "http://127.0.0.1:${builtins.toString cfg.port}${cfg.nginxConfig.subpath}/api";
336345
extraConfig = ''
337346
proxy_set_header Host $server_name;
338347
'';

0 commit comments

Comments
 (0)