@jetstart/core 1.5.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,10 +3,12 @@
3
3
  * Serves APKs, handles REST endpoints
4
4
  */
5
5
  import { Server } from 'http';
6
+ import { ServerSession } from '../types';
6
7
  export interface HttpServerConfig {
7
8
  port: number;
8
9
  host: string;
9
10
  getLatestApk?: () => string | null;
11
+ getCurrentSession?: () => ServerSession | null;
10
12
  }
11
13
  export declare function createHttpServer(config: HttpServerConfig): Promise<Server>;
12
14
  //# sourceMappingURL=http.d.ts.map
@@ -17,7 +17,7 @@ async function createHttpServer(config) {
17
17
  // Setup middleware
18
18
  (0, middleware_1.setupMiddleware)(app);
19
19
  // Setup routes
20
- (0, routes_1.setupRoutes)(app, config.getLatestApk);
20
+ (0, routes_1.setupRoutes)(app, config.getLatestApk, config.getCurrentSession);
21
21
  // Start server
22
22
  return new Promise((resolve, reject) => {
23
23
  const server = app.listen(config.port, config.host, () => {
@@ -116,6 +116,7 @@ class JetStartServer extends events_1.EventEmitter {
116
116
  port: this.config.httpPort,
117
117
  host: this.config.host,
118
118
  getLatestApk: () => this.latestApkPath,
119
+ getCurrentSession: () => this.currentSession,
119
120
  });
120
121
  // Start WebSocket server
121
122
  const wsResult = await (0, websocket_1.createWebSocketServer)({
@@ -3,5 +3,6 @@
3
3
  * REST API endpoints
4
4
  */
5
5
  import { Express } from 'express';
6
- export declare function setupRoutes(app: Express, getLatestApk?: () => string | null): void;
6
+ import { ServerSession } from '../types';
7
+ export declare function setupRoutes(app: Express, getLatestApk?: () => string | null, getCurrentSession?: () => ServerSession | null): void;
7
8
  //# sourceMappingURL=routes.d.ts.map
@@ -13,7 +13,41 @@ const session_1 = require("../utils/session");
13
13
  const qr_1 = require("../utils/qr");
14
14
  const shared_1 = require("@jetstart/shared");
15
15
  const sessionManager = new session_1.SessionManager();
16
- function setupRoutes(app, getLatestApk) {
16
+ function setupRoutes(app, getLatestApk, getCurrentSession) {
17
+ // Root Redirect -> Web Emulator
18
+ app.get('/', (req, res) => {
19
+ try {
20
+ const session = getCurrentSession?.();
21
+ // If no session active, just show simple status
22
+ if (!session) {
23
+ return res.send(`
24
+ <h1>JetStart Core Running</h1>
25
+ <p>No active session found. Please restart 'jetstart dev'.</p>
26
+ `);
27
+ }
28
+ // Construct redirect URL
29
+ const webUrl = 'https://web.jetstart.site';
30
+ const host = req.hostname;
31
+ const port = req.socket.localPort || 8765;
32
+ const wsPort = shared_1.DEFAULT_WS_PORT;
33
+ const queryParams = new URLSearchParams({
34
+ host: host,
35
+ port: String(port),
36
+ wsPort: String(wsPort), // Typically 8766
37
+ sessionId: session.id,
38
+ token: session.token,
39
+ version: shared_1.JETSTART_VERSION,
40
+ projectName: session.projectName || 'JetStart Project'
41
+ });
42
+ const redirectUrl = `${webUrl}?${queryParams.toString()}`;
43
+ // Redirect to web emulator
44
+ res.redirect(redirectUrl);
45
+ }
46
+ catch (err) {
47
+ console.error('Redirect error:', err);
48
+ res.status(500).send('Failed to redirect to emulator');
49
+ }
50
+ });
17
51
  // Health check
18
52
  app.get('/health', (req, res) => {
19
53
  res.json({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetstart/core",
3
- "version": "1.5.3",
3
+ "version": "1.6.0",
4
4
  "description": "Build server and orchestration for JetStart",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -33,8 +33,8 @@
33
33
  },
34
34
  "homepage": "https://github.com/dev-phantom/jetstart#readme",
35
35
  "dependencies": {
36
- "@jetstart/shared": "^1.5.3",
37
- "@jetstart/logs": "^1.5.3",
36
+ "@jetstart/shared": "^1.6.0",
37
+ "@jetstart/logs": "^1.6.0",
38
38
  "express": "^4.18.2",
39
39
  "ws": "^8.14.2",
40
40
  "chokidar": "^3.5.3",
@@ -8,11 +8,13 @@ import { Server } from 'http';
8
8
  import { setupMiddleware } from './middleware';
9
9
  import { setupRoutes } from './routes';
10
10
  import { log } from '../utils/logger';
11
+ import { ServerSession } from '../types';
11
12
 
12
13
  export interface HttpServerConfig {
13
14
  port: number;
14
15
  host: string;
15
16
  getLatestApk?: () => string | null;
17
+ getCurrentSession?: () => ServerSession | null;
16
18
  }
17
19
 
18
20
  export async function createHttpServer(config: HttpServerConfig): Promise<Server> {
@@ -22,7 +24,7 @@ export async function createHttpServer(config: HttpServerConfig): Promise<Server
22
24
  setupMiddleware(app);
23
25
 
24
26
  // Setup routes
25
- setupRoutes(app, config.getLatestApk);
27
+ setupRoutes(app, config.getLatestApk, config.getCurrentSession);
26
28
 
27
29
  // Start server
28
30
  return new Promise((resolve, reject) => {
@@ -105,6 +105,7 @@ export class JetStartServer extends EventEmitter {
105
105
  port: this.config.httpPort,
106
106
  host: this.config.host,
107
107
  getLatestApk: () => this.latestApkPath,
108
+ getCurrentSession: () => this.currentSession,
108
109
  });
109
110
 
110
111
  // Start WebSocket server
@@ -8,11 +8,55 @@ import path from 'path';
8
8
  import fs from 'fs';
9
9
  import { SessionManager } from '../utils/session';
10
10
  import { generateQRCode } from '../utils/qr';
11
- import { JETSTART_VERSION } from '@jetstart/shared';
11
+ import { JETSTART_VERSION, DEFAULT_WS_PORT } from '@jetstart/shared';
12
+ import { ServerSession } from '../types';
12
13
 
13
14
  const sessionManager = new SessionManager();
14
15
 
15
- export function setupRoutes(app: Express, getLatestApk?: () => string | null): void {
16
+ export function setupRoutes(
17
+ app: Express,
18
+ getLatestApk?: () => string | null,
19
+ getCurrentSession?: () => ServerSession | null
20
+ ): void {
21
+ // Root Redirect -> Web Emulator
22
+ app.get('/', (req: Request, res: Response) => {
23
+ try {
24
+ const session = getCurrentSession?.();
25
+
26
+ // If no session active, just show simple status
27
+ if (!session) {
28
+ return res.send(`
29
+ <h1>JetStart Core Running</h1>
30
+ <p>No active session found. Please restart 'jetstart dev'.</p>
31
+ `);
32
+ }
33
+
34
+ // Construct redirect URL
35
+ const webUrl = 'https://web.jetstart.site';
36
+ const host = req.hostname;
37
+ const port = req.socket.localPort || 8765;
38
+ const wsPort = DEFAULT_WS_PORT;
39
+
40
+ const queryParams = new URLSearchParams({
41
+ host: host,
42
+ port: String(port),
43
+ wsPort: String(wsPort), // Typically 8766
44
+ sessionId: session.id,
45
+ token: session.token,
46
+ version: JETSTART_VERSION,
47
+ projectName: session.projectName || 'JetStart Project'
48
+ });
49
+
50
+ const redirectUrl = `${webUrl}?${queryParams.toString()}`;
51
+
52
+ // Redirect to web emulator
53
+ res.redirect(redirectUrl);
54
+
55
+ } catch (err: any) {
56
+ console.error('Redirect error:', err);
57
+ res.status(500).send('Failed to redirect to emulator');
58
+ }
59
+ });
16
60
  // Health check
17
61
  app.get('/health', (req: Request, res: Response) => {
18
62
  res.json({