UNPKG

react-cosmos

Version:

Sandbox for developing and testing UI components in isolation

23 lines (22 loc) 745 B
import http from 'http'; import https from 'https'; import { getHttpsCreds } from './httpsCreds.js'; export async function createHttpServer(config, requestListener) { const server = config.https ? https.createServer(await getHttpsCreds(config), requestListener) : http.createServer(requestListener); async function start() { await new Promise(resolve => { if (config.host === null) { server.listen(config.port, resolve); } else { server.listen(config.port, config.host, resolve); } }); } async function stop() { await new Promise(resolve => server.close(resolve)); } return { server, start, stop }; }