-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwatch.js
54 lines (49 loc) · 1.16 KB
/
watch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const config = require("config");
const nodemon = require("nodemon");
const localtunnel = require("localtunnel");
const PORT = process.env.PORT || 8000;
const opts = config.get("localtunnel");
(async () => {
let url;
const tunnel = await new Promise((resolve, reject) =>
localtunnel(
PORT,
Object.assign({}, opts || {}, { port: PORT }),
(err, tunnel) => {
if (err) {
reject(err);
} else {
url = tunnel.url;
console.log("Waiting 5 seconds...");
setTimeout(() => {
console.log("App starting on " + url);
resolve(tunnel);
}, 5000);
}
}
)
);
nodemon({
script: "src/index.js",
ignore: [".git", "node_modules/**/node_modules"],
env: {
SITE_URL: url,
PORT: PORT,
},
ext: "js json",
execMap: {
js: "babel-node",
},
});
tunnel
.on("error", function (err) {
throw err;
})
.on("close", function () {
console.log("Localtunnel closed");
process.exit();
})
.on("request", function (info) {
console.log(new Date().toString(), info.method, info.path);
});
})();