-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathhttpServer.js
More file actions
23 lines (18 loc) · 709 Bytes
/
Copy pathhttpServer.js
File metadata and controls
23 lines (18 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';
import {NativeEventEmitter, NativeModules} from 'react-native';
const Server = NativeModules.HttpServer;
const ServerEventEmitter = new NativeEventEmitter(Server);
module.exports = {
start: function (port, serviceName, callback) {
if (port === 80) {
throw "Invalid server port specified. Port 80 is reserved.";
}
Server.start(port, serviceName);
ServerEventEmitter.addListener('httpServerResponseReceived', callback);
},
stop: () => {
Server.stop();
ServerEventEmitter.removeAllListeners('httpServerResponseReceived');
},
respond: (requestId, code, type, body) => Server.respond(requestId, code, type, body)
}