Skip to content

Commit 2dfa670

Browse files
fix: reconnect issue (#216)
* chore: add demo for easier debugging * fix: handle reconnect with correct states, urls and reconnect tokens
1 parent cad8b35 commit 2dfa670

File tree

17 files changed

+3948
-32
lines changed

17 files changed

+3948
-32
lines changed

demo/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

demo/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# CodeSandbox SDK Demo
2+
3+
This is a demo application showcasing the CodeSandbox SDK with an Express server running Vite middleware in a single process.
4+
5+
## Architecture
6+
7+
The demo uses a TypeScript Express server that integrates Vite as middleware, providing:
8+
- **API routes** for backend functionality
9+
- **Vite dev server** for hot module replacement and frontend serving
10+
- **Single process** - no need to run separate frontend/backend servers
11+
12+
## Setup
13+
14+
1. Build the SDK from the root directory:
15+
```bash
16+
npm run build
17+
```
18+
19+
2. Install demo dependencies:
20+
```bash
21+
cd demo
22+
npm install
23+
```
24+
25+
3. Run the demo:
26+
```bash
27+
npm run dev
28+
```
29+
30+
This will start the server at `http://localhost:3000` with both API routes and the Vite frontend.
31+
32+
## Available Scripts
33+
34+
- `npm run dev` - Start the TypeScript server with Vite middleware
35+
- `npm run build` - Build the frontend for production
36+
- `npm run preview` - Preview production build
37+
38+
## Usage
39+
40+
### Frontend (Vite + React)
41+
42+
The demo app imports the SDK from the local build using:
43+
44+
```typescript
45+
import CodeSandbox from '@codesandbox/sdk'
46+
```
47+
48+
You can modify `src/App.tsx` to add your SDK demo code.
49+
50+
### Backend (Express + Vite Middleware)
51+
52+
The Express server (`server.ts`) provides:
53+
54+
- API routes (mounted before Vite middleware):
55+
- `GET /api/health` - Health check endpoint
56+
- `GET /api/example` - Example API endpoint
57+
- Vite middleware for serving the frontend with HMR
58+
59+
Add your custom API routes in `server.ts` before the Vite middleware setup to support your SDK demo needs (like handling API keys, proxying requests, etc.).

demo/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>CodeSandbox SDK Demo</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)