forked from Alwinator/react-native-http-bridge-refurbished
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpServer.js
More file actions
22 lines (17 loc) · 650 Bytes
/
Copy pathhttpServer.js
File metadata and controls
22 lines (17 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
import {DeviceEventEmitter, NativeModules} from 'react-native';
const 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: () => {
Server.stop();
DeviceEventEmitter.removeAllListeners('httpServerResponseReceived');
},
respond: (requestId, code, type, body) => Server.respond(requestId, code, type, body)
}