mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 07:05:24 +00:00
simpler wait-for-port
This commit is contained in:
@@ -39,7 +39,6 @@
|
|||||||
"source-map-support": "^0.5.3",
|
"source-map-support": "^0.5.3",
|
||||||
"tslib": "^1.8.1",
|
"tslib": "^1.8.1",
|
||||||
"url-parse": "^1.2.0",
|
"url-parse": "^1.2.0",
|
||||||
"wait-port": "^0.2.2",
|
|
||||||
"walk-sync": "^0.3.2",
|
"walk-sync": "^0.3.2",
|
||||||
"webpack": "^3.10.0"
|
"webpack": "^3.10.0"
|
||||||
},
|
},
|
||||||
@@ -72,7 +71,7 @@
|
|||||||
"pretest": "npm run build",
|
"pretest": "npm run build",
|
||||||
"build": "rollup -c",
|
"build": "rollup -c",
|
||||||
"dev": "rollup -cw",
|
"dev": "rollup -cw",
|
||||||
"prepublish": "npm test",
|
"prepublishOnly": "npm test",
|
||||||
"update_mime_types": "curl http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types | grep -e \"^[^#]\" > src/middleware/mime-types.md"
|
"update_mime_types": "curl http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types | grep -e \"^[^#]\" > src/middleware/mime-types.md"
|
||||||
},
|
},
|
||||||
"repository": "https://github.com/sveltejs/sapper",
|
"repository": "https://github.com/sveltejs/sapper",
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ export default async function dev() {
|
|||||||
|
|
||||||
deferreds.client.promise.then(() => {
|
deferreds.client.promise.then(() => {
|
||||||
function restart() {
|
function restart() {
|
||||||
wait_for_port(3000, deferreds.server.fulfil); // TODO control port
|
wait_for_port(3000).then(deferreds.server.fulfil); // TODO control port
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proc) {
|
if (proc) {
|
||||||
|
|||||||
@@ -88,8 +88,7 @@ export default async function exporter(export_dir: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_for_port(port, () => {
|
wait_for_port(port)
|
||||||
handle(new URL(origin)) // TODO all static routes
|
.then(() => handle(new URL(origin))) // TODO all static routes
|
||||||
.then(() => proc.kill())
|
.then(() => proc.kill());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,25 @@
|
|||||||
import waitPort from 'wait-port';
|
import * as net from 'net';
|
||||||
|
|
||||||
export function wait_for_port(port: number, cb: () => void) {
|
export function wait_for_port(port: number, timeout = 5000) {
|
||||||
waitPort({ port }).then(cb);
|
return new Promise((fulfil, reject) => {
|
||||||
|
get_connection(port, fulfil);
|
||||||
|
setTimeout(() => reject(new Error(`timed out waiting for connection`)), timeout);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// import * as net from 'net';
|
export function get_connection(port: number, cb: () => void) {
|
||||||
|
const socket = net.createConnection(port, 'localhost', () => {
|
||||||
|
cb();
|
||||||
|
socket.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
// export function wait_for_port(port: number, cb: () => void) {
|
socket.on('error', err => {
|
||||||
// const socket = net.createConnection(port, 'localhost', () => {
|
setTimeout(() => {
|
||||||
// cb();
|
get_connection(port, cb);
|
||||||
// socket.destroy();
|
}, 10);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// socket.on('error', err => {
|
setTimeout(() => {
|
||||||
// setTimeout(() => {
|
socket.destroy();
|
||||||
// wait_for_port(port, cb);
|
}, 1000);
|
||||||
// }, 100);
|
}
|
||||||
// });
|
|
||||||
|
|
||||||
// setTimeout(() => {
|
|
||||||
// socket.destroy();
|
|
||||||
// }, 100);
|
|
||||||
// }
|
|
||||||
Reference in New Issue
Block a user