本文整理汇总了TypeScript中get-port.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript get-port.default方法的具体用法?TypeScript get-port.default怎么用?TypeScript get-port.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类get-port
的用法示例。
在下文中一共展示了get-port.default方法的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}`);
}
}
示例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);
}
});
});
}
示例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()
})
示例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()
})
示例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)
})
示例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)
})
示例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()
})
示例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');
}