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
3 changes: 3 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"react": "^19.2.5",
"react-dom": "^19.2.5",
"use-intl": "^4.11.0",
"ws": "^8.21.0",
"zod": "^4.4.1"
},
"devDependencies": {
Expand All @@ -32,8 +33,10 @@
"@types/node": "^25.6.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@types/ws": "^8.18.1",
"@vitnode/config": "workspace:*",
"@vitnode/nodemailer": "workspace:*",
"@vitnode/blog": "workspace:*",
"dotenv": "^17.4.2",
"eslint": "^10.2.1",
"react-email": "^6.1.5",
Expand Down
11 changes: 10 additions & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { serve } from "@hono/node-server";
import { serve, upgradeWebSocket } from "@hono/node-server";
import { OpenAPIHono } from "@hono/zod-openapi";
import { VitNodeAPI } from "@vitnode/core/api/config";
import { handleVitNodeWebSocket } from "@vitnode/core/ws/handle";
import { WebSocketServer } from "ws";

import { vitNodeApiConfig } from "./vitnode.api.config.js";

Expand All @@ -11,10 +13,17 @@ VitNodeAPI({
vitNodeApiConfig,
});

const wss = new WebSocketServer({ noServer: true });

app.get("/ws", upgradeWebSocket(handleVitNodeWebSocket()));

serve(
{
fetch: app.fetch,
port: 8080,
websocket: {
server: wss,
},
},
info => {
const initMessage = "\x1b[34m[VitNode]\x1b[0m";
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/vitnode.api.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { blogApiPlugin } from "@vitnode/blog/config.api";
import { buildApiConfig } from "@vitnode/core/vitnode.config";
import { NodemailerEmailAdapter } from "@vitnode/nodemailer";
import { config } from "dotenv";
Expand All @@ -11,7 +12,7 @@ export const POSTGRES_URL =
process.env.POSTGRES_URL ?? "postgresql://root:root@localhost:5432/vitnode";

export const vitNodeApiConfig = buildApiConfig({
plugins: [],
plugins: [blogApiPlugin()],
pathToMessages: async path => await import(`./locales/${path}`),
dbProvider: drizzle({
connection: POSTGRES_URL,
Expand Down
1 change: 1 addition & 0 deletions apps/docs/content/docs/dev/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"email",
"sso",
"cron",
"websocket",
"---Frontend---",
"layouts-and-pages",
"admin-page",
Expand Down
15 changes: 15 additions & 0 deletions apps/docs/content/docs/dev/redis.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Redis
description: Enhance your application's performance and scalability.
---

<Callout type="warn" title="This documentation is under construction! 🚧">
We're working hard to bring you the best documentation experience.
</Callout>

## Going to production - websockets

The connection list lives in memory on a single server. If you run **several
server instances** behind a load balancer, a `broadcast` or `sendToUser` only
reaches the clients on the same instance. To fix that, share the messages
between instances with a pub/sub like **Redis**.
Loading
Loading