Skip to content

Commit 169e419

Browse files
authored
Merge pull request #152 from xsnippet/xsnippet-api-devserver
Add docker-compose.yml for launching devenv
2 parents efc07a4 + 876ab60 commit 169e419

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ The source code is distributed under MIT license. Feel free to contribute by
1212
any means. Your feedback is welcome as well!
1313

1414

15+
Develompent
16+
-----------
17+
18+
By default, the source code points to a production instance of XSnippet API.
19+
In order to avoid spamming production database, one can easily setup a local
20+
devenv using `docker-compose`, e.g.
21+
22+
```bash
23+
$ npm run devenv-up
24+
```
25+
26+
and starting XSnippet Web configured to use this local version, e.g.
27+
28+
```bash
29+
$ npm run devenv-start
30+
```
31+
32+
1533
Links
1634
-----
1735

devenv/docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: "3.9"
2+
services:
3+
xsnippet-api:
4+
image: xsnippet/xsnippet-api:v1.1.0
5+
environment:
6+
- XSNIPPET_SERVER_HOST=0.0.0.0
7+
- XSNIPPET_SERVER_PORT=8000
8+
- XSNIPPET_DATABASE_CONNECTION_URI=mongodb://database:27017/xsnippet
9+
- XSNIPPET_SNIPPET_SYNTAXES=rust,python,javascript,markdown,json,d,css,html
10+
ports:
11+
- 8000:8000
12+
depends_on:
13+
- database
14+
xsnippet-web-backend:
15+
image: xsnippet/xsnippet-web-backend:v1.0.0
16+
environment:
17+
- XSNIPPET_WEB_PROXY_HOST=0.0.0.0
18+
- XSNIPPET_WEB_PROXY_PORT=8000
19+
- XSNIPPET_API_URL=http://xsnippet-api:8000
20+
ports:
21+
- 8001:8000
22+
depends_on:
23+
- xsnippet-api
24+
database:
25+
image: mongo:3

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@
9090
"lint": "eslint --ignore-path .gitignore --ext js,jsx .",
9191
"build": "webpack --mode production",
9292
"start": "webpack-dev-server --mode development --open",
93-
"test": "jest --coverage"
93+
"test": "jest --coverage",
94+
"devenv-start": "API_BASE_URI=\"http://localhost:8080/_api\" RAW_SNIPPET_URI_FORMAT=\"http://localhost:8080/_web-backend/snippets/%s/raw\" npm start",
95+
"devenv-up": "docker-compose -f devenv/docker-compose.yml up"
9496
},
9597
"private": true
9698
}

webpack.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ module.exports = () => {
124124

125125
devServer: {
126126
historyApiFallback: true,
127+
proxy: {
128+
'/_api': {
129+
target: 'http://localhost:8000',
130+
pathRewrite: { '^/_api': '' },
131+
headers: { Host: 'localhost:8000/_api' },
132+
},
133+
'/_web-backend': {
134+
target: 'http://localhost:8001',
135+
pathRewrite: { '^/_web-backend': '' },
136+
},
137+
},
127138
},
128139

129140
entry: {

0 commit comments

Comments
 (0)