mirror of
https://github.com/hzrd149/nsite-gateway.git
synced 2025-06-23 12:05:01 +00:00
fallback to public folder when using nsite homepage
This commit is contained in:
parent
9a04f63712
commit
14d767114a
10
src/index.ts
10
src/index.ts
@ -60,18 +60,24 @@ app.use(async (ctx, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// handle nsite requests
|
// handle nsite requests
|
||||||
app.use(async (ctx) => {
|
app.use(async (ctx, next) => {
|
||||||
let pubkey = await resolvePubkeyFromHostname(ctx.hostname);
|
let pubkey = await resolvePubkeyFromHostname(ctx.hostname);
|
||||||
|
|
||||||
|
let fallthrough = true;
|
||||||
if (!pubkey && NSITE_HOMEPAGE && (!PUBLIC_DOMAIN || ctx.hostname === PUBLIC_DOMAIN)) {
|
if (!pubkey && NSITE_HOMEPAGE && (!PUBLIC_DOMAIN || ctx.hostname === PUBLIC_DOMAIN)) {
|
||||||
const parsed = nip19.decode(NSITE_HOMEPAGE);
|
const parsed = nip19.decode(NSITE_HOMEPAGE);
|
||||||
// TODO: use the relays in the nprofile
|
// TODO: use the relays in the nprofile
|
||||||
|
|
||||||
if (parsed.type === "nprofile") pubkey = parsed.data.pubkey;
|
if (parsed.type === "nprofile") pubkey = parsed.data.pubkey;
|
||||||
else if (parsed.type === "npub") pubkey = parsed.data;
|
else if (parsed.type === "npub") pubkey = parsed.data;
|
||||||
|
|
||||||
|
// Fallback to public dir if path cannot be found on the nsite homepage
|
||||||
|
if (pubkey) fallthrough = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pubkey) {
|
if (!pubkey) {
|
||||||
|
if (fallthrough) return next();
|
||||||
|
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
ctx.body = fs.readFileSync(path.resolve(__dirname, "../public/404.html"), "utf-8");
|
ctx.body = fs.readFileSync(path.resolve(__dirname, "../public/404.html"), "utf-8");
|
||||||
return;
|
return;
|
||||||
@ -95,6 +101,8 @@ app.use(async (ctx) => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
|
if (fallthrough) return next();
|
||||||
|
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
ctx.body = `Not Found: no events found\npath: ${ctx.path}\nkind: ${NSITE_KIND}\npubkey: ${pubkey}\nrelays: ${relays.join(", ")}`;
|
ctx.body = `Not Found: no events found\npath: ${ctx.path}\nkind: ${NSITE_KIND}\npubkey: ${pubkey}\nrelays: ${relays.join(", ")}`;
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user