本文整理汇总了TypeScript中get-port类的典型用法代码示例。如果您正苦于以下问题:TypeScript get-port类的具体用法?TypeScript get-port怎么用?TypeScript get-port使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了get-port类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: handleVisualDevConfigLoaded
function* handleVisualDevConfigLoaded() {
while(true) {
yield take(CHILD_DEV_SERVER_STARTED);
let server: express.Express;
let httpServer: http.Server;
if (httpServer) {
httpServer.close();
}
const port = yield getPort();
server = express();
server.use((req, res, next) => {
req.socket.on("error", (e) => {
console.warn(e);
});
next();
});
// TODO - dispatch express server initialized
httpServer = server.listen(port);
yield put(expressServerStarted(server, port));
console.log(`HTTP server listening on port ${port}`);
}
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:27,代码来源:express-server.ts
示例2: listen
async listen(port?: number) {
if (!port && process.env.NODE_ENV === 'production') {
port = 80;
}
if (!port) {
port = process.env.PORT;
}
if (!port) {
port = await getPort(3000);
}
this.port = port;
await this.nextApp.prepare();
return new Promise((resolve, reject) => {
this.expressApp.listen(this.port, err => {
if (err) {
reject(err);
}
else {
resolve(this.port);
}
});
});
}
开发者ID:benangmerah,项目名称:benangmerah,代码行数:26,代码来源:Server.ts
示例3: getPort
test('fires onConnect upon successful connection', async done => {
const port = await getPort()
createClosingServer(port)
const client = createClient({ createSocket, port, onDisconnect: done })
client.connect()
})
开发者ID:chenrui2014,项目名称:reactotron,代码行数:7,代码来源:on-disconnect.test.ts
示例4: getPort
test('plugins support send', async done => {
const port = await getPort()
const server = new WebSocket.Server({ port })
let capturedSend: any
// the plugin to extract the send function
const plugin = reactotron => {
capturedSend = reactotron.send
return {}
}
// create the client, add the plugin, and connect
const client = createClient({
createSocket,
port,
onConnect: () => capturedSend(mock.type, mock.payload),
}).use(plugin)
// the server waits for the command
server.on('connection', socket => {
// fires the server receives a command
socket.on('message', message => {
const { type, payload } = JSON.parse(message.toString())
if (type === 'client.intro') return
expect(type).toEqual(mock.type)
expect(payload).toEqual(mock.payload)
done()
server.close()
})
})
client.connect()
})
开发者ID:chenrui2014,项目名称:reactotron,代码行数:34,代码来源:plugin-send.test.ts
示例5: getPort
test('connect returns itself', async done => {
const port = await getPort()
createClosingServer(port, done)
const client = createClient({ createSocket, port })
const connectClient = client.connect()
expect(connectClient).toBe(client)
})
开发者ID:chenrui2014,项目名称:reactotron,代码行数:8,代码来源:connect.test.ts
示例6: async
test("sets the started flag", async () => {
const port = await getPort()
const server = createServer({ port })
expect(server.started).toBe(false)
server.start()
expect(server.started).toBe(true)
server.stop()
expect(server.started).toBe(false)
})
开发者ID:TheIdhem,项目名称:reactotron,代码行数:9,代码来源:started.test.ts
示例7: getPort
test('plugins support onConnect', async done => {
const port = await getPort()
createClosingServer(port)
// this plugin supports onDisconnect
const plugin = reactotron => ({ onDisconnect: done })
// create a client & add the plugin
createClient({ createSocket, port })
.use(plugin)
.connect()
})
开发者ID:chenrui2014,项目名称:reactotron,代码行数:12,代码来源:plugin-on-disconnect.test.ts
示例8: reload
export async function main() {
const app = express();
const ctx: KaedeContext = {
client: new Client(config),
baseUrl: null,
staticRoot: resolve(args.static),
};
const loader = new ModuleLoader<KaedeHandler>(script);
function reload() {
loader.reload();
console.log('updated');
}
keypress.on('enter', reload);
keypress.on('return', reload);
app.use(express.static(ctx.staticRoot));
app.post('*', middleware(config), (req, res) => {
// early return
res.end();
const events: Array<WebhookEvent> = req.body.events;
events.forEach(async event => {
const sender = createSender(ctx.client, event);
try {
for await (const message of loader.content(event, ctx)) {
await sender.send(message);
}
} catch (err) {
console.error(err);
} finally {
await sender.flush();
}
});
});
const port = await getPort();
await new Promise(resolve => app.listen(port, resolve));
ctx.baseUrl = await ngrok(port);
console.log(`Listening at ${ctx.baseUrl}`);
const baseUrlWithoutProtocol = ctx.baseUrl.split('//')[1]; // remove https://
await clipboardy.write(baseUrlWithoutProtocol);
console.log(`${baseUrlWithoutProtocol} is copied to the clipboard\n`);
keypress.init();
console.log('Press Enter/Return to reload the bot script');
console.log('Press Ctrl+C/D to quit');
}
开发者ID:utatti,项目名称:kaede,代码行数:52,代码来源:index.ts
注:本文中的get-port类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论