UNPKG

705 BJavaScriptView Raw
1import connect from 'connect';
2import cowsay from 'cowsay';
3import path from 'path';
4import portscanner from 'portscanner';
5import serveStatic from 'serve-static';
6
7// Configuration for the server.
8const PORT = 9999;
9const MAX_PORT = PORT + 100;
10const HOST = '127.0.0.1';
11
12const app = connect();
13
14const verbs = [
15 'Chewing the cud',
16 'Grazing',
17 'Mooing',
18 'Lowing',
19 'Churning the cream'
20];
21
22app.use(serveStatic(path.join(__dirname, '..')));
23
24portscanner.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});