in src/server/serverBase.ts [44:79]
public init() {
const app = express();
app.use(bodyParser.json());
app.use(cors({
credentials: true,
origin: 'http://127.0.0.1:3000',
}));
app.post(dataPlaneUri, handleDataPlanePostRequest);
app.post(eventHubMonitorUri, handleEventHubMonitorPostRequest);
app.post(eventHubStopUri, handleEventHubStopPostRequest);
app.get(readFileUri, handleReadFileRequest);
app.get(readFileNaiveUri, handleReadFileNaiveRequest);
app.get(getDirectoriesUri, handleGetDirectoriesRequest);
//initialize a simple http server
const server = http.createServer(app);
//start the server
server.listen(this.port).on('error', () => { throw new Error(
`Failed to start the app on port ${this.port} as it is in use.
You can still view static pages, but requests cannot be made to the services if the port is still occupied.
To get around with the issue, configure a custom port by setting the system environment variable 'AZURE_IOT_EXPLORER_PORT' to an available port number.
To learn more, please visit https://github.com/Azure/azure-iot-explorer/wiki/FAQ`); });
//initialize the WebSocket server instance
wss = new WebSocket.Server({ server });
wss.on('connection', (_ws: WebSocket) => {
if (_ws && _ws.readyState === WebSocket.OPEN) {
ws = _ws;
}
else {
ws = null;
}
});
}