當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript get-port類代碼示例

本文整理匯總了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;未經允許,請勿轉載。