Skip to content

codepilots/metro-local

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Metro

MIT licensed npm package version facebook/metro/nightly-tests Code coverage Follow @MetroBundler on Twitter

🚇 The JavaScript bundler for React Native.

  • 🚅 Fast: We aim for sub-second reload cycles, fast startup and quick bundling speeds.
  • ⚖️ Scalable: Works with thousands of modules in a single application.
  • ⚛️ Integrated: Supports every React Native project out of the box.

Installation

Metro is included with React Native — see the React Native docs to quickly get started ⏱️.

To add Metro to an existing project, see our Getting Started guide.

Documentation

All available documentation, including on configuring Metro, can be found on the Metro website.

Source code for documentation is located in this repository under docs/.

Contributing

Metro was previously part of the react-native repository. In this standalone repository it is easier for the team working on Metro to respond to issues and pull requests. See react-native#13976 for the initial announcement.

Meta has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Read our contributing guide to learn about our development process, how to propose bug fixes and improvements, and how to build and test your changes to Metro.

Discussions

Larger discussions and proposals concerning React Native and Metro are discussed in @react-native-community/discussions-and-proposals.

License

Metro is MIT licensed, as found in the LICENSE file.

Reverse Proxy and baseUrl Support

This is exploritory functionalityby @codepilots. It may or may not work, use at your own risk!

Overview

This fork adds robust support for running Metro behind a reverse proxy by introducing a configurable baseUrl option. All URLs and file paths served by the Metro server—including bundles, source maps, HMR, delta, assets, symbolicate, and all other endpoints—are now correctly prefixed with the configured baseUrl. This ensures Metro can be hosted at a non-root path and all outgoing URLs and endpoint routing will work as expected.

Approach

  • Configurable baseUrl: The server reads a baseUrl from the config and uses it to prefix all served URLs and endpoint matches.
  • Endpoint Routing: All endpoint handlers in Server.js use utilities to strip or add the baseUrl for correct internal routing and external URL generation.
  • Outgoing URLs: All outgoing URLs in responses (such as asset metadata, bundle URLs, source maps, and module source URLs in source maps and error stacks) are generated with the baseUrl prefix.
  • Asset Metadata: The .assets endpoint and asset metadata now use the baseUrl-prefixed /assets as their publicPath.
  • Source Maps: Module source URLs in source maps are baseUrl-prefixed when using server-relative paths.
  • HMR and Async Split Bundles: All dynamic bundle URLs are constructed with the baseUrl.

Key Changes

  • Added _prefixWithBaseUrl and _stripBaseUrl utilities in Server.js for consistent path handling.
  • Updated all endpoint routing and outgoing URL generation to use these utilities.
  • Ensured asset metadata and module source URLs are always baseUrl-aware.
  • Updated HMR and async split bundle URL construction to use baseUrl.
  • All changes are Flow-typed and maintain compatibility with the existing Metro codebase.

Usage

To use Metro behind a reverse proxy, set the baseUrl option in your Metro config:

// metro.config.js
module.exports = {
  baseUrl: '/my/proxy/path',
  // ...other config
};

All served URLs and endpoint routing will now respect this baseUrl.


About

🚇 The JavaScript bundler for React Native - fork for reverse-proxy VM use

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.9%
  • Other 0.1%