@callstack/repack-dev-server 5.0.6 → 6.0.0-canary-20250430091845

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,6 +3,7 @@ import middie from '@fastify/middie';
3
3
  import fastifySensible from '@fastify/sensible';
4
4
  import { createDevMiddleware } from '@react-native/dev-middleware';
5
5
  import Fastify from 'fastify';
6
+ import { createProxyMiddleware } from 'http-proxy-middleware';
6
7
  import apiPlugin from './plugins/api/apiPlugin.js';
7
8
  import compilerPlugin from './plugins/compiler/compilerPlugin.js';
8
9
  import devtoolsPlugin from './plugins/devtools/devtoolsPlugin.js';
@@ -85,6 +86,9 @@ export async function createServer(config) {
85
86
  enableNewDebugger: true,
86
87
  },
87
88
  });
89
+ const proxyMiddlewares = options.proxy?.map((proxyOptions) => {
90
+ return createProxyMiddleware(proxyOptions);
91
+ });
88
92
  // Register plugins
89
93
  await instance.register(fastifySensible);
90
94
  await instance.register(middie);
@@ -120,6 +124,10 @@ export async function createServer(config) {
120
124
  });
121
125
  // Register dev middleware
122
126
  instance.use(devMiddleware.middleware);
127
+ // Register proxy middlewares
128
+ proxyMiddlewares?.forEach((proxyMiddleware) => {
129
+ instance.use(proxyMiddleware);
130
+ });
123
131
  // Register routes
124
132
  instance.get('/', async () => delegate.messages.getHello());
125
133
  instance.get('/status', async () => delegate.messages.getStatus());
@@ -1,12 +1,22 @@
1
1
  import fastifyPlugin from 'fastify-plugin';
2
2
  import { Symbolicator } from './Symbolicator.js';
3
+ function getStackFromRequestBody(request) {
4
+ let body;
5
+ if (request.headers['content-type'] === 'application/json') {
6
+ // RN >= 0.79 uses application/json
7
+ body = request.body;
8
+ }
9
+ else {
10
+ // RN < 0.79 uses text/plain
11
+ body = JSON.parse(request.body);
12
+ }
13
+ return body.stack;
14
+ }
3
15
  async function symbolicatePlugin(instance, { delegate, }) {
4
16
  const symbolicator = new Symbolicator(delegate.symbolicator);
5
17
  instance.post('/symbolicate', async (request, reply) => {
6
- // React Native sends stack as JSON but tests content-type to text/plain, so
7
- // we cannot use JSON schema to validate the body.
8
18
  try {
9
- const { stack } = JSON.parse(request.body);
19
+ const stack = getStackFromRequestBody(request);
10
20
  const platform = Symbolicator.inferPlatformFromStack(stack);
11
21
  if (!platform) {
12
22
  request.log.debug({ msg: 'Received stack', stack });
package/dist/types.d.ts CHANGED
@@ -1,10 +1,15 @@
1
1
  import type { ServerOptions as HttpsServerOptions } from 'node:https';
2
2
  import type { FastifyBaseLogger } from 'fastify';
3
+ import type { Options as ProxyOptions } from 'http-proxy-middleware';
3
4
  import type { CompilerDelegate } from './plugins/compiler/types.js';
4
5
  import type { CodeFrame, InputStackFrame, ReactNativeStackFrame, StackFrame, SymbolicatorDelegate, SymbolicatorResults } from './plugins/symbolicate/types.js';
5
6
  import type { NormalizedOptions } from './utils/normalizeOptions.js';
6
7
  export type { CompilerDelegate };
7
8
  export type { CodeFrame, InputStackFrame, ReactNativeStackFrame, StackFrame, SymbolicatorDelegate, SymbolicatorResults, };
9
+ interface ProxyConfig extends ProxyOptions {
10
+ path?: ProxyOptions['pathFilter'];
11
+ context?: ProxyOptions['pathFilter'];
12
+ }
8
13
  export interface DevServerOptions {
9
14
  /**
10
15
  * Hostname or IP address under which to run the development server.
@@ -16,6 +21,7 @@ export interface DevServerOptions {
16
21
  port?: number;
17
22
  /** Whether to enable Hot Module Replacement. */
18
23
  hot?: boolean;
24
+ proxy?: ProxyConfig[];
19
25
  /** Options for running the server as HTTPS. If `undefined`, the server will run as HTTP. */
20
26
  server?: 'http' | 'https' | {
21
27
  type: 'http';
@@ -1,10 +1,12 @@
1
1
  import type { ServerOptions as HttpsServerOptions } from 'node:https';
2
+ import type { Options as ProxyOptions } from 'http-proxy-middleware';
2
3
  import type { Server } from '../types.js';
3
4
  export interface NormalizedOptions {
4
5
  host: string;
5
6
  port: number;
6
7
  https: HttpsServerOptions | undefined;
7
8
  hot: boolean;
9
+ proxy: ProxyOptions[] | undefined;
8
10
  url: string;
9
11
  disableRequestLogging: boolean;
10
12
  rootDir: string;
@@ -6,6 +6,21 @@ function normalizeHttpsOptions(serverOptions) {
6
6
  }
7
7
  return undefined;
8
8
  }
9
+ function normalizeProxyOptions(proxyOptions, fallbackTarget) {
10
+ if (proxyOptions) {
11
+ return proxyOptions.map((options) => {
12
+ const { context, path, pathFilter, target, ...rest } = options;
13
+ return {
14
+ ...rest,
15
+ // webpack dev server compatible aliases for pathFilter
16
+ pathFilter: pathFilter ?? context ?? path,
17
+ // assume that if the target is not provided, we target our own DevServer
18
+ target: target ?? fallbackTarget,
19
+ };
20
+ });
21
+ }
22
+ return undefined;
23
+ }
9
24
  export function normalizeOptions(options) {
10
25
  const host = options.host ?? 'localhost';
11
26
  const port = options.port ?? 8081;
@@ -13,12 +28,14 @@ export function normalizeOptions(options) {
13
28
  const hot = options.hot ?? false;
14
29
  const protocol = https ? 'https' : 'http';
15
30
  const url = `${protocol}://${host}:${options.port}`;
31
+ const proxy = normalizeProxyOptions(options.proxy, url);
16
32
  return {
17
33
  // webpack dev server compatible options
18
34
  host,
19
35
  port,
20
36
  https,
21
37
  hot,
38
+ proxy,
22
39
  url,
23
40
  // fastify options
24
41
  disableRequestLogging: !options.logRequests,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@callstack/repack-dev-server",
3
3
  "description": "A bundler-agnostic development server for React Native applications as part of @callstack/repack.",
4
4
  "license": "MIT",
5
- "version": "5.0.6",
5
+ "version": "6.0.0-canary-20250430091845",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
@@ -39,6 +39,7 @@
39
39
  "fastify": "^4.24.3",
40
40
  "fastify-favicon": "^4.3.0",
41
41
  "fastify-plugin": "^4.5.1",
42
+ "http-proxy-middleware": "^3.0.3",
42
43
  "launch-editor": "^2.10.0",
43
44
  "open": "^10.1.0",
44
45
  "pretty-format": "^28.1.0",
@@ -49,7 +50,7 @@
49
50
  "@types/babel__code-frame": "^7.0.6",
50
51
  "@types/node": "^18",
51
52
  "@types/ws": "^8.18.0",
52
- "typescript": "^5.7.2"
53
+ "typescript": "^5.8.3"
53
54
  },
54
55
  "scripts": {
55
56
  "build": "tsc -b",