{"_id":"@activatortube/react-native-web-server","_rev":"4-e4ff701917d4da3285fb3656e0c5ed5e","name":"@activatortube/react-native-web-server","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.1-alpha.1":{"name":"@activatortube/react-native-web-server","version":"0.0.1-alpha.1","author":"","license":"Apache-2.0","_id":"@activatortube/react-native-web-server@0.0.1-alpha.1","maintainers":[{"name":"wheelerlee","email":"490386516@qq.com"}],"homepage":"https://github.com/WheelerLee/react-native-web-server","bugs":{"url":"https://github.com/WheelerLee/react-native-web-server/issues"},"dist":{"shasum":"ac147c258a92e30498e7a853db6dbec370d6537d","tarball":"https://registry.npmjs.org/@activatortube/react-native-web-server/-/react-native-web-server-0.0.1-alpha.1.tgz","fileCount":27,"integrity":"sha512-2HZlIqShlBitSFXgWc5KMlJ9XrildnPiet68Dl9WP/v8vZChS8tx8Dyg48TGhY1quCh6z31L2308EwaWGRQPvw==","signatures":[{"sig":"MEYCIQCmOdfxtkMzLQUIbHO2PTGVJC/MTmX8FXoNYDmzRse1EgIhAIwo1CSTV5GNiWPaNne62x6MC9egWhlPc2xgOKPAPJSn","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39596},"main":"dist/commonjs/index.js","types":"dist/typescript/index.d.ts","module":"dist/module/index.js","scripts":{"build":"npm run clean && npm run build:typescript && npm run build:commonjs && npm run build:module","clean":"rm -rf dist","typecheck":"tsc --noEmit","build:module":"tsc --module esnext --outDir dist/module --skipLibCheck","build:commonjs":"tsc --module commonjs --outDir dist/commonjs --verbatimModuleSyntax false --skipLibCheck","prepublishOnly":"npm run build","build:typescript":"tsc --declaration --outDir dist/typescript --emitDeclarationOnly"},"_npmUser":{"name":"wheelerlee","email":"490386516@qq.com"},"repository":{"url":"git+https://github.com/WheelerLee/react-native-web-server.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight React Native web server to serve app sandbox directories as static files.","directories":{},"_nodeVersion":"20.19.4","react-native":"src/index.ts","codegenConfig":{"name":"RNWebServerSpec","type":"modules","android":{"javaPackageName":"com.activatortube.rnwebserver"},"jsSrcsDir":"./src"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"yarn@4.5.1","devDependencies":{"react":"19.1.0","typescript":"^5.9.3","react-native":"^0.80.1"},"peerDependencies":{"react":">=18.0.0","react-native":">=0.72.0"},"_npmOperationalInternal":{"tmp":"tmp/react-native-web-server_0.0.1-alpha.1_1765267589485_0.6870288690447857","host":"s3://npm-registry-packages-npm-production"}},"0.0.1-alpha.2":{"name":"@activatortube/react-native-web-server","version":"0.0.1-alpha.2","author":"","license":"Apache-2.0","_id":"@activatortube/react-native-web-server@0.0.1-alpha.2","maintainers":[{"name":"wheelerlee","email":"490386516@qq.com"}],"homepage":"https://github.com/WheelerLee/react-native-web-server","bugs":{"url":"https://github.com/WheelerLee/react-native-web-server/issues"},"dist":{"shasum":"152e8fb25dc56d9efae18c53501100e8fed86005","tarball":"https://registry.npmjs.org/@activatortube/react-native-web-server/-/react-native-web-server-0.0.1-alpha.2.tgz","fileCount":28,"integrity":"sha512-9iplfOOiXx2FQL1BdixJdUGJGYCxgsgc33LVCi7Gm3E/42FBDfi/JeUseLuV0jA/cGLtV198V4ntBAKn4sbe0A==","signatures":[{"sig":"MEUCIQDZrwBxgXF2z8xblehqARu0VZdLigAu6iDKgX+NT9HmKAIgPQQQx5d5Kt0monYxhpilj8gHEM/cLMKn8uL7oAXcXzc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39921},"main":"dist/commonjs/index.js","types":"dist/typescript/index.d.ts","module":"dist/module/index.js","scripts":{"build":"npm run clean && npm run build:typescript && npm run build:commonjs && npm run build:module","clean":"rm -rf dist","typecheck":"tsc --noEmit","build:module":"tsc --module esnext --outDir dist/module --skipLibCheck","build:commonjs":"tsc --module commonjs --outDir dist/commonjs --verbatimModuleSyntax false --skipLibCheck","prepublishOnly":"npm run build","build:typescript":"tsc --declaration --outDir dist/typescript --emitDeclarationOnly"},"_npmUser":{"name":"wheelerlee","email":"490386516@qq.com"},"repository":{"url":"git+https://github.com/WheelerLee/react-native-web-server.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight React Native web server to serve app sandbox directories as static files.","directories":{},"_nodeVersion":"20.19.4","react-native":"src/index.ts","codegenConfig":{"name":"RNWebServerSpec","type":"modules","android":{"javaPackageName":"com.activatortube.rnwebserver"},"jsSrcsDir":"./src"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"yarn@4.5.1","devDependencies":{"react":"19.1.0","typescript":"^5.9.3","react-native":"^0.80.1"},"peerDependencies":{"react":">=18.0.0","react-native":">=0.72.0"},"_npmOperationalInternal":{"tmp":"tmp/react-native-web-server_0.0.1-alpha.2_1765268700084_0.5610353401876089","host":"s3://npm-registry-packages-npm-production"}},"1.0.0-rc.1":{"name":"@activatortube/react-native-web-server","version":"1.0.0-rc.1","keywords":["react-native","web-server","http-server","static-files","webview","local-server","react-native-module"],"author":"","license":"Apache-2.0","_id":"@activatortube/react-native-web-server@1.0.0-rc.1","maintainers":[{"name":"wheelerlee","email":"490386516@qq.com"}],"homepage":"https://github.com/WheelerLee/react-native-web-server","bugs":{"url":"https://github.com/WheelerLee/react-native-web-server/issues"},"dist":{"shasum":"a20873aff8bbd7976bb1a382391f2335d11ed978","tarball":"https://registry.npmjs.org/@activatortube/react-native-web-server/-/react-native-web-server-1.0.0-rc.1.tgz","fileCount":31,"integrity":"sha512-UaOSJwxaf83S0ahGfA+jPUQDUSE7rYlajq3w5rg1zxV2u4ySpNFJewt0Ieu55XBA6LsgNcd4AT6+nFN0WwXSgw==","signatures":[{"sig":"MEYCIQCYo6ZkciZ7XP3fa/85V/iNXNHz1eZaS9sbuaVBSMY2nQIhAOQp49fr7bO4e2BXhWg0TuqhlI4gBiJIzurMKvkTwy9L","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":47744},"main":"dist/commonjs/index.js","types":"dist/typescript/index.d.ts","module":"dist/module/index.js","scripts":{"build":"npm run clean && npm run build:typescript && npm run build:commonjs && npm run build:module","clean":"rm -rf dist","typecheck":"tsc --noEmit","build:module":"tsc --module esnext --outDir dist/module --skipLibCheck","build:commonjs":"tsc --module commonjs --outDir dist/commonjs --verbatimModuleSyntax false --skipLibCheck","prepublishOnly":"npm run build","build:typescript":"tsc --declaration --outDir dist/typescript --emitDeclarationOnly"},"_npmUser":{"name":"wheelerlee","email":"490386516@qq.com"},"repository":{"url":"git+https://github.com/WheelerLee/react-native-web-server.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight React Native web server to serve app sandbox directories as static files.","directories":{},"_nodeVersion":"20.19.4","react-native":"src/index.ts","codegenConfig":{"name":"RNWebServerSpec","type":"modules","android":{"javaPackageName":"com.activatortube.rnwebserver"},"jsSrcsDir":"./src"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"yarn@4.5.1","devDependencies":{"react":"19.1.0","typescript":"^5.9.3","react-native":"^0.80.1"},"peerDependencies":{"react":">=18.0.0","react-native":">=0.72.0"},"_npmOperationalInternal":{"tmp":"tmp/react-native-web-server_1.0.0-rc.1_1765273774642_0.23574772957980406","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"@activatortube/react-native-web-server","version":"1.0.0","description":"A lightweight React Native web server to serve app sandbox directories as static files.","keywords":["react-native","web-server","http-server","static-files","webview","local-server","react-native-module"],"publishConfig":{"access":"public"},"types":"dist/typescript/index.d.ts","main":"dist/commonjs/index.js","module":"dist/module/index.js","react-native":"src/index.ts","scripts":{"clean":"rm -rf dist","build":"npm run clean && npm run build:typescript && npm run build:commonjs && npm run build:module","build:typescript":"tsc --declaration --outDir dist/typescript --emitDeclarationOnly","build:commonjs":"tsc --module commonjs --outDir dist/commonjs --verbatimModuleSyntax false --skipLibCheck","build:module":"tsc --module esnext --outDir dist/module --skipLibCheck","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"homepage":"https://github.com/WheelerLee/react-native-web-server","repository":{"type":"git","url":"git+https://github.com/WheelerLee/react-native-web-server.git"},"peerDependencies":{"react":">=18.0.0","react-native":">=0.72.0"},"devDependencies":{"react":"19.1.0","react-native":"^0.80.1","typescript":"^5.9.3"},"author":"","license":"Apache-2.0","packageManager":"yarn@4.5.1","codegenConfig":{"name":"RNWebServerSpec","type":"modules","jsSrcsDir":"./src","android":{"javaPackageName":"com.activatortube.rnwebserver"}},"_id":"@activatortube/react-native-web-server@1.0.0","bugs":{"url":"https://github.com/WheelerLee/react-native-web-server/issues"},"_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-WgFdJneaO95WPfYEBLZeEVHRtWYao6W8Vlfx0ZoSFCRqHfeu1j1uEZRztUfmhPInXjbuUXumvXn5dtc8L+EE6A==","shasum":"f0523d445e7457ae77ba54bd6a92622dde126c20","tarball":"https://registry.npmjs.org/@activatortube/react-native-web-server/-/react-native-web-server-1.0.0.tgz","fileCount":31,"unpackedSize":47851,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCQmsVGqPVADWBHGQ509u3zObZ+DhFMVVmU2Q5ivbu1QQIhAIaIP536VB4XHAfYDD7JvYn7nEQxDkDoryfe6xr6e7gr"}]},"_npmUser":{"name":"wheelerlee","email":"490386516@qq.com"},"directories":{},"maintainers":[{"name":"wheelerlee","email":"490386516@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-native-web-server_1.0.0_1765276051612_0.2782727546694015"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-09T08:06:29.347Z","modified":"2025-12-09T10:27:31.986Z","0.0.1-alpha.1":"2025-12-09T08:06:29.643Z","0.0.1-alpha.2":"2025-12-09T08:25:00.224Z","1.0.0-rc.1":"2025-12-09T09:49:34.800Z","1.0.0":"2025-12-09T10:27:31.777Z"},"bugs":{"url":"https://github.com/WheelerLee/react-native-web-server/issues"},"license":"Apache-2.0","homepage":"https://github.com/WheelerLee/react-native-web-server","keywords":["react-native","web-server","http-server","static-files","webview","local-server","react-native-module"],"repository":{"type":"git","url":"git+https://github.com/WheelerLee/react-native-web-server.git"},"description":"A lightweight React Native web server to serve app sandbox directories as static files.","maintainers":[{"name":"wheelerlee","email":"490386516@qq.com"}],"readme":"# @activatortube/react-native-web-server\n\n一个轻量级的 React Native Web 服务器，用于将应用沙盒目录作为静态文件提供服务。\n\n[English](./README.md) | [中文文档](./README.zh.md)\n\n## 功能特性\n\n- 🚀 轻量级、高性能的本地 Web 服务器\n- 📁 支持多个路径前缀映射\n- 🔄 可以动态启动和停止服务器\n- 📱 支持 iOS 和 Android 平台\n- 🎯 完美配合 WebView 使用\n\n> **⚠️ 注意：** 本库目前仅支持 React Native 的新架构（New Architecture），暂不支持旧架构（Old Architecture）。欢迎通过 Pull Request 贡献代码以支持旧架构！\n\n## 使用场景\n\n这个库非常适合需要通过 Web 服务器提供本地文件，而不是直接通过 WebView 的 `file://` 协议加载文件的场景。以下是相比直接加载本地文件的主要优势：\n\n### 相比直接使用 WebView 加载本地文件的优势\n\n1. **跨域资源共享 (CORS) 支持**\n   - 通过 HTTP 提供的 Web 内容可以正确处理 CORS 策略\n   - 允许加载外部资源和 API，不受 CORS 限制\n   - 直接的 `file://` 协议通常会阻止跨域请求\n\n2. **网络可访问性**\n   - 支持同一局域网内其他设备的访问\n   - 非常适合在多个设备上同时进行测试和调试\n   - 允许与网络上的其他应用或服务共享内容\n\n3. **标准 HTTP 协议**\n   - 使用标准 HTTP/HTTPS 协议，确保与 Web 库更好的兼容性\n   - 许多 Web 框架和库期望使用 HTTP URL\n   - 更好地支持 Service Workers、WebSockets 等功能\n\n4. **动态内容服务**\n   - 可以提供动态生成或修改的内容\n   - 更容易实现路由和路径映射\n   - 更灵活的文件服务策略\n\n5. **更好的安全模型**\n   - HTTP 服务器可以实现适当的安全头\n   - 对内容交付和访问策略有更多控制\n\n### 使用场景\n\n- 提供需要 HTTP 协议的 HTML5 游戏或交互式 Web 内容\n- 在多个设备上同时测试 Web 内容\n- 与其他应用或服务共享本地内容\n- 提供需要与需要 HTTP 上下文的 Web API 配合使用的内容\n- 需要网络访问的调试和开发场景\n\n## 安装\n\n使用 npm 或 yarn 安装：\n\n```bash\nnpm install @activatortube/react-native-web-server\n# 或\nyarn add @activatortube/react-native-web-server\n```\n\n### iOS 安装\n\n对于 iOS，需要安装 CocoaPods 依赖：\n\n```bash\ncd ios && pod install\n```\n\n## 使用方法\n\n### 基本示例\n\n以下示例展示了如何在 React Native 应用中使用 `@activatortube/react-native-web-server` 来启动一个本地 Web 服务器，并在 WebView 中显示内容：\n\n```tsx\nimport { useEffect, useState } from 'react';\nimport { View, StyleSheet } from 'react-native';\nimport WebServer from '@activatortube/react-native-web-server';\nimport WebView from 'react-native-webview';\nimport RNFS from 'react-native-fs';\n\nfunction AppContent() {\n  const [port, setPort] = useState(0);\n\n  useEffect(() => {\n    WebServer.start([{\n      prefix: '/',\n      path: Platform.OS === 'android' ? RNFS.CachesDirectoryPath : RNFS.DocumentDirectoryPath,\n    }]).then((result) => {\n      console.log('WebServer started at port', result);\n      setPort(result);\n    }).catch((error) => {\n      console.error('WebServer start failed', error);\n    });\n\n    return () => {\n      WebServer.stop();\n    }\n  }, []);\n\n  return (\n    <View style={styles.container}>\n      <WebView\n        source={{ uri: `http://localhost:${port}/` }}\n      />\n    </View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  container: {\n    flex: 1,\n  },\n});\n```\n\n### 多路径映射\n\n你也可以配置多个路径前缀映射：\n\n```tsx\nWebServer.start([\n  {\n    prefix: '/',\n    path: RNFS.CachesDirectoryPath,\n  },\n  {\n    prefix: '/game',\n    path: RNFS.DocumentDirectoryPath + '/game',\n  },\n]);\n```\n\n## API 文档\n\n### `WebServer.start(handlers: HandlerOptions[]): Promise<number>`\n\n启动 Web 服务器。\n\n**参数：**\n- `handlers`: 路径处理器配置数组\n  - `prefix`: 请求的路径前缀，根目录为 `/`\n  - `path`: 需要被访问的文件夹路径。例如：如果 `prefix` 使用 `/game`，那么访问 `/game/index.html` 会访问到 `path/index.html`\n\n**返回值：**\n- `Promise<number>`: 返回服务器启动的端口号\n\n**注意：** 可以重复调用，如果已经启动了，那么将停止上次启动的服务，并启动新的服务。\n\n### `WebServer.stop(): void`\n\n停止 Web 服务器。\n\n## 截图\n\n![Screenshot 1](./screenshots/Screenshot1.png)\n\n*在同一个 app 内通过 WebView 直接访问 web 服务器*\n\n![Screenshot 2](./screenshots/ScreenShot2.png)\n\n*在局域网中使用 IP 地址和端口从其他设备访问 web 服务器*\n\n## 依赖要求\n\n- React >= 18.0.0\n- React Native >= 0.72.0\n\n## 许可证\n\nApache-2.0\n\n## 相关链接\n\n- [GitHub 仓库](https://github.com/WheelerLee/react-native-web-server)\n\n","readmeFilename":"README.zh.md"}