1 | import connect from 'connect';
|
2 | import cowsay from 'cowsay';
|
3 | import path from 'path';
|
4 | import portscanner from 'portscanner';
|
5 | import serveStatic from 'serve-static';
|
6 |
|
7 |
|
8 | const PORT = 9999;
|
9 | const MAX_PORT = PORT + 100;
|
10 | const HOST = '127.0.0.1';
|
11 |
|
12 | const app = connect();
|
13 |
|
14 | const verbs = [
|
15 | 'Chewing the cud',
|
16 | 'Grazing',
|
17 | 'Mooing',
|
18 | 'Lowing',
|
19 | 'Churning the cream'
|
20 | ];
|
21 |
|
22 | app.use(serveStatic(path.join(__dirname, '..')));
|
23 |
|
24 | portscanner.findAPortNotInUse(PORT, MAX_PORT, HOST, (error, port) => {
|
25 | if (error) {
|
26 | throw error;
|
27 | }
|
28 |
|
29 | process.stdout.write(cowsay.say({
|
30 | text: `${verbs[Math.floor(Math.random() * 5)]} on ${HOST}:${port}`
|
31 | }) + '\n\n');
|
32 |
|
33 | app.listen(port);
|
34 | });
|