forked from react-native-oh-library/react-native-http-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpServer.js
29 lines (24 loc) · 886 Bytes
/
httpServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* @providesModule react-native-http-server
*/
'use strict';
import { DeviceEventEmitter } from 'react-native';
import { NativeModules } from 'react-native';
import { TurboModuleRegistry } from "react-native";
var Server = TurboModuleRegistry ? TurboModuleRegistry.get('ReactNativeHttpBridge') : 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.removeAllListeners('httpServerResponseReceived');
},
respond: function (requestId, code, type, body) {
Server.respond(requestId, code, type, body);
}
}