Skip to content

Commit c667a09

Browse files
committed
Allow debugging and stepping from Google Chrome
Enabled debugging through the chrome debugger and added documentation on how to use this functionality.
1 parent 4017812 commit c667a09

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ You can install additional dependencies by including a `package.json` file next
8484

8585
## Developing with the template
8686

87+
Livereload is enabled automatically when running in development mode. You can embed the template easily in a running mu.semte.ch stack by launching it in the docker-compose.yml with the correct links. If desired, the chrome inspecor can be attached during development, giving advanced javascript debugging features.
88+
89+
### Live reload
8790
When developing, you can use the template image, mount the volume with your sources in `/app` and add a link to the database. Set the `NODE_ENV` environment variable to `development`. The service will live-reload on changes. You'll need to restart the container when you define additional dependencies in your `package.json`.
8891

8992
docker run --link virtuoso:database \
@@ -93,4 +96,49 @@ When developing, you can use the template image, mount the volume with your sour
9396
--name my-js-test \
9497
semtech/mu-javascript-template
9598

99+
### Develop in mu.semte.ch stack
100+
When developing inside an existing mu.semte.ch stack, it is easiest to set the development mode and mount the sources directly. This makes it easy to setup links to the database and the dispatcher.
101+
102+
Optionally, you can publish the microservice on a different port, so you can access it directly without the dispatcher. In the example below, port 8888 is used to access the service directly. We set the path to our sources directly, ensuring we can develop the microservice in its original place.
103+
104+
yourMicroserviceName:
105+
image: semtech/mu-javascript-template
106+
ports:
107+
- 8888:80
108+
environment:
109+
NODE_ENV: "development"
110+
links:
111+
- db:database
112+
volumes:
113+
- /absolute/path/to/your/sources/:/app/
114+
115+
### Attach the Chrome debugger
116+
When running in development mode, you can attach the chrome debugger to your microservice and add breakpoints as you're used to. The chrome debugger requires port 9229 to be forwarded, and your service to run in development mode. After launching your service, open Google Chrome or Chromium, and visit [chrome://inspect/](chrome://inspect/).
117+
118+
Running through docker run, you could access the service as follows:
119+
120+
docker run --link virtuoso:database \
121+
-v `pwd`:/app \
122+
-p 8888:80 \
123+
-p 9229:9229 \
124+
-e NODE_ENV=development \
125+
--name my-js-test \
126+
semtech/mu-javascript-template
127+
128+
Now open Chromium, and visit [chrome://inspect/](chrome://inspect/). Once the service is launched, a remote target on localhost should pop up.
129+
130+
When running inside a mu.semte.ch stack, you could mount your sources and connect to known microservices as follows:
131+
132+
yourMicroserviceName:
133+
image: semtech/mu-javascript-template
134+
ports:
135+
- 8888:80
136+
- 9229:9229
137+
environment:
138+
NODE_ENV: "development"
139+
links:
140+
- db:database
141+
volumes:
142+
- /absolute/path/to/your/sources/:/app/
96143

144+
Now open Chromium, and visit [chrome://inspect/](chrome://inspect/). Once the service is launched, a remote target on localhost should pop up.

start.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
ps aux | grep babel-node | awk '{print $1}' | xargs kill -9
55

66
## Run using babel
7-
NODE_PATH=`pwd`/node_modules:`pwd`/helpers:$NODE_PATH ./node_modules/babel-cli/bin/babel-node.js app.js --presets es2015,es2016,es2017
7+
if [ "$NODE_ENV" == "development" ]
8+
then
9+
NODE_PATH=`pwd`/node_modules:`pwd`/helpers:$NODE_PATH ./node_modules/babel-cli/bin/babel-node.js app.js --inspect=0.0.0.0:9229 --presets es2015,es2016,es2017
10+
else
11+
NODE_PATH=`pwd`/node_modules:`pwd`/helpers:$NODE_PATH ./node_modules/babel-cli/bin/babel-node.js app.js --presets es2015,es2016,es2017
12+
fi

0 commit comments

Comments
 (0)