本文整理汇总了TypeScript中http.Server类的典型用法代码示例。如果您正苦于以下问题:TypeScript Server类的具体用法?TypeScript Server怎么用?TypeScript Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
return protractorUtils.findFreeTcpPort().then(port => {
const app = new http.Server();
app.on('request', (req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World');
res.end('\n');
});
browser.baseUrl = `http://localhost:${port}`;
return new Promise(resolve => { app.listen(port, () => { resolve(); }); });
});
示例2: catch
.catch(error => {
startupError = error;
try {
wsServer.close();
} catch (_error) {}
try {
httpServer.close();
} catch (_error) {}
})
示例3: init
export async function init(){
console.log('starting IDE');
await check_lockfile()
.catch( (e: Error) => console.log('error checking lockfile', e) );
// setup webserver
const app: express.Application = express();
const server: http.Server = new http.Server(app);
setup_routes(app);
// start serving the IDE on port 80
server.listen(80, () => console.log('listening on port', 80) );
// initialise websocket
socket_manager.init(server);
TerminalManager.init();
}
示例4: Promise
return new Promise((resolve) => {
const server = this.server = createServer((request: IncomingMessage, response: ServerResponse) => {
return this._handler(request, response);
});
this._sessions = {};
this._codeCache = {};
const sockets: Socket[] = [];
// If sockets are not manually destroyed then Node.js will keep itself running until they all expire
after(server, 'close', function () {
let socket: Socket;
while ((socket = sockets.pop())) {
socket.destroy();
}
});
server.on('connection', socket => {
this.executor.log('HTTP connection opened');
sockets.push(socket);
// Disabling Nagle improves server performance on low-latency connections, which are more common
// during testing than high-latency connections
socket.setNoDelay(true);
socket.on('close', function () {
let index = sockets.indexOf(socket);
index !== -1 && sockets.splice(index, 1);
});
});
this._wsServer = new WebSocket.Server({ port: this.port + 1 });
this._wsServer.on('connection', client => {
this.executor.log('WebSocket connection opened:', client);
this._handleWebSocket(client);
});
this._wsServer.on('error', error => {
this.executor.emit('error', error);
});
server.listen(this.port, resolve);
});
示例5: post
function post(data): Promise<string> {
const options = {
host: "localhost",
port: server.address().port,
path: "/analyze",
method: "POST",
headers: {
"Content-Type": "application/json",
},
};
return new Promise((resolve, reject) => {
let response = "";
const req = http.request(options, res => {
res.on("data", chunk => {
response += chunk;
});
res.on("end", () => resolve(response));
});
req.on("error", reject);
req.write(data);
req.end();
});
}
示例6: after
after(() => {
if (serverToClose) {
serverToClose.close();
}
});
示例7: after
after(() => {
if (server) {
server.close();
}
});
示例8: Promise
return new Promise((resolve, reject) => {
server.close((err) => {
if (err) {
return reject(err);
}
resolve();
})
})
示例9: listen
listen(): void {
this.server.listen(this.port, () => {
console.log(` > Running socket on port: ${this.port}`);
});
this.io.on('connection', (socket: socketio.Socket) => {
socket.on('live_data', (value: boolean) => {
this.useTrainingData = value;
});
});
}
示例10: after
after(() => {
server.close();
let cache = require.cache;
for (let path of Object.keys(cache)) {
if (/(?:[\\/]modules|-routes)[\\/]/.test(path)) {
delete cache[path];
}
}
});