HTTP Transport
This guide demonstrates a Teleportal server setup using only HTTP connections: HTTP POST & Server-Sent Events (SSE). This is useful for environments where WebSocket upgrades are blocked.
What it demonstrates
Section titled “What it demonstrates”- Setting up a Teleportal server with HTTP transport only
- Using Server-Sent Events (SSE) for real-time synchronization
- Client connection using the
ProviderAPI with HTTP transport
Server Setup
Section titled “Server Setup”import { Server } from "teleportal/server";import { getHttpHandlers } from "teleportal/http";
const server = new Server({ getStorage: async (ctx) => { // Your storage implementation return documentStorage; },});
// HTTP handlersconst handlers = getHttpHandlers({ server, onConnect: async (request) => { // Extract context from request return { context: { userId: "user-123" }, }; },});Client Setup
Section titled “Client Setup”The Provider automatically uses HTTP transport when WebSocket is not available:
import { Provider } from "teleportal/providers";
// Provider will automatically use HTTP/SSE if WebSocket failsconst provider = await Provider.create({ url: "https://example.com", document: "my-document",});
await provider.synced;How It Works
Section titled “How It Works”- HTTP POST: Client sends messages via HTTP POST requests
- Server-Sent Events: Server sends messages via SSE connection
- Automatic Fallback: Provider automatically falls back to HTTP if WebSocket fails
Next Steps
Section titled “Next Steps”- Fallback Connection - Automatic fallback from WebSocket to HTTP
- Authentication - Add authentication to your server