mirror of
https://github.com/status-im/react-native-http-bridge.git
synced 2026-08-31 14:51:14 +00:00
29 lines
753 B
JavaScript
29 lines
753 B
JavaScript
/**
|
|
* @providesModule react-native-http-server
|
|
*/
|
|
'use strict';
|
|
|
|
import {DeviceEventEmitter} from 'react-native';
|
|
import {NativeModules} from 'react-native';
|
|
var Server = NativeModules.HttpServer;
|
|
|
|
module.exports = {
|
|
start: function (port, serviceName, callback) {
|
|
if (port == 80) {
|
|
throw "Invalid server port specified. Port 80 is reserved.";
|
|
}
|
|
|
|
Server.start(port, serviceName);
|
|
DeviceEventEmitter.addListener('httpServerResponseReceived', callback);
|
|
},
|
|
|
|
stop: function () {
|
|
Server.stop();
|
|
DeviceEventEmitter.removeListener('httpServerResponseReceived');
|
|
},
|
|
|
|
respond: function (requestId, code, type, body) {
|
|
Server.respond(requestId, code, type, body);
|
|
}
|
|
}
|