-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(web): make node getting code less goofy and more reusable, ignore link types for now
- Loading branch information
1 parent
4f0eaa1
commit fca2b77
Showing
9 changed files
with
575 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createServer } from "node:http"; | ||
import auth from "@stardust/common/auth"; | ||
import { fromNodeHeaders } from "better-auth/node"; | ||
import { createProxyMiddleware } from "http-proxy-middleware"; | ||
import next from "next"; | ||
const dev = process.env.NODE_ENV !== "production"; | ||
import type { Socket } from "node:net"; | ||
import { getConfig } from "@stardust/config"; | ||
const { nostrUrl } = getConfig(); | ||
const port = Number.parseInt(process.env.PORT as string) || 3000; | ||
if (process.argv.includes("--turbo")) { | ||
process.env.TURBOPACK = "1"; | ||
} | ||
console.log( | ||
`✨ Stardust: Starting ${dev ? "development" : "production"} server ${process.env.TURBOPACK ? "With turbopack" : ""}...`, | ||
); | ||
const httpServer = createServer(); | ||
const nostrProxy = createProxyMiddleware({ | ||
target: nostrUrl, | ||
ws: true, | ||
}); | ||
const app = next({ | ||
dev, | ||
port, | ||
httpServer, | ||
}); | ||
await app.prepare(); | ||
httpServer.on("request", app.getRequestHandler()); | ||
httpServer.on("upgrade", (req, socket, head) => | ||
req.url?.startsWith("/nostr") | ||
? nostrProxy.upgrade(req, socket as Socket, head) | ||
: app.getUpgradeHandler()(req, socket, head), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { stardustConnector } from "@stardust/common/daemon/client"; | ||
import { getConfig } from "@stardust/config"; | ||
import type { SelectSession } from "@stardust/db"; | ||
|
||
export function getNode(session: SelectSession) { | ||
const sessionNode = getConfig().nodes.find(({ id }) => id === session.node); | ||
if (!sessionNode) throw new Error("well this is awkward why does the session not have a node"); | ||
return stardustConnector(`http://${sessionNode.hostname}:${sessionNode.port || 4000}`, sessionNode.token); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.