{"id":21658671,"url":"https://github.com/futurepress/react-native-static-server","last_synced_at":"2025-07-17T21:31:25.774Z","repository":{"id":17501774,"uuid":"82117257","full_name":"futurepress/react-native-static-server","owner":"futurepress","description":"HTTP static file server for React Native","archived":false,"fork":false,"pushed_at":"2023-05-24T11:09:02.000Z","size":1276,"stargazers_count":352,"open_issues_count":46,"forks_count":176,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-05-29T14:25:42.179Z","etag":null,"topics":["react-native"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/futurepress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-15T23:26:35.000Z","updated_at":"2024-06-18T12:42:43.995Z","dependencies_parsed_at":"2024-06-18T12:42:33.523Z","dependency_job_id":"5c66c5fd-564b-4f11-906f-2ea6f8125f58","html_url":"https://github.com/futurepress/react-native-static-server","commit_stats":{"total_commits":63,"total_committers":16,"mean_commits":3.9375,"dds":0.4126984126984127,"last_synced_commit":"d0c4cb0feae233634ef26fc33118f258192c7b7d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurepress%2Freact-native-static-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurepress%2Freact-native-static-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurepress%2Freact-native-static-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurepress%2Freact-native-static-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/futurepress","download_url":"https://codeload.github.com/futurepress/react-native-static-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226304907,"owners_count":17603716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react-native"],"created_at":"2024-11-25T09:29:38.471Z","updated_at":"2024-11-25T09:29:54.757Z","avatar_url":"https://github.com/futurepress.png","language":"Java","funding_links":[],"categories":["网络编程","Java"],"sub_categories":["Spring Cloud框架"],"readme":"\n# react-native-static-server\n\nA cross platform component for serving static assets with React Native.\n\n## Getting started\n\n`$ npm install react-native-static-server --save`\n\n### Installation\n\nFrom react-native 0.60 autolinking will take care of the link step but don't forget to run pod install\n\n`$ react-native link react-native-static-server`\n\n## Usage\n\nDeclare the `StaticServer` with a port or use the default `0` to pick a random available port.\n\n```javascript\nimport StaticServer from 'react-native-static-server';\n\nlet server = new StaticServer(8080);\n\n// Start the server\nserver.start().then((url) =\u003e {\n  console.log(\"Serving at URL\", url);\n});\n\n// Stop the server\nserver.stop();\n\n// Check if native server running\nconst isRunning = await server.isRunning()\n// isRunning - true/false\n```\n\n`StaticServer` serves from the document directory (default) or takes an optional absolute path to serve from.\n\nFor instance, using [react-native-fs](https://github.com/johanneslumpe/react-native-fs) you can get the document directory and specify a directory from there.\n\n#### Default (document directory)\n\n```javascript\nimport StaticServer from 'react-native-static-server';\nimport RNFS from 'react-native-fs';\n\n// create a path you want to write to\nlet path = RNFS.DocumentDirectoryPath + '/www';\n\nlet server = new StaticServer(8080, path);\n```\n\n#### Custom folder (iOS)\n\n##### Create the folder for static files\n\nCreate a folder in your project's top-level directory (usually next to your node_modules and index.js file), and put the files you want to access over http in there.\n\n##### Add folder (static files) to XCode\n\nThis folder **must be added to XCode** so it gets bundled with the app.\n\nIn XCode, `Project Navigator` right click in the folder project → `Add files to \"\u003cproject\u003e\"` → Select the static folder **and clic options (Uncheck copy items if needed, Create folder references)** so don't duplicate files → Clic Add.\n\nWhen the app gets bundled, this folder will be next to the compiled app, so using `MainBundlePath` property from `react-native-fs` you can access to the directory.\n\n```javascript\nimport StaticServer from 'react-native-static-server';\nimport RNFS from 'react-native-fs';\n\n// path where files will be served from (index.html here)\nlet path = RNFS.MainBundlePath + '/www';\n\nlet server = new StaticServer(8080, path);\n```\n\nIf the server should only be accessible from within the app, set `localOnly` to `true`\n\n```javascript\nimport StaticServer from 'react-native-static-server';\n\n// Just set options with defaults\nlet server = new StaticServer({localOnly : true });\n// Or also valid are:\nlet server = new StaticServer(8080, {localOnly : true });\nlet server = new StaticServer(8080, path, {localOnly : true });\n\n```\n\nIf the server should not pause when the app is in the background, set `keepAlive` to `true`\n\n```javascript\nlet server = new StaticServer({keepAlive : true });\n```\n\nPassing `0` as the port number will cause a random port to be assigned every time the server starts.\nIt will reset to a new random port each time the server unpauses, so this should only be used with `keepAlive`.\n\n```javascript\nlet server = new StaticServer(0, {keepAlive : true });\n```\n\n## Credits\n\n* iOS server: [GCDWebServer](https://github.com/swisspol/GCDWebServer)\n* Android server: [NanoHttpd Webserver](https://github.com/NanoHttpd/nanohttpd)\n\nThanks to [CorHttpd](https://github.com/floatinghotpot/cordova-httpd) and [react-native-httpserver](https://gitlab.com/base.io/react-native-httpserver#README) for the basis of this library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturepress%2Freact-native-static-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuturepress%2Freact-native-static-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturepress%2Freact-native-static-server/lists"}