-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
380 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'**/*.{js,ts,json,yml}': 'eslint --cache --fix', | ||
"src/**/*.{js,ts}": ["jest --bail --passWithNoTests --findRelatedTests"] | ||
'(src|tests|scripts)/**/*.{js,ts,json,yml}': 'eslint --cache --fix', | ||
'src/**/*.{js,ts}': 'jest --bail --passWithNoTests --findRelatedTests', | ||
'examples/**/*.js': 'eslint --cache --fix' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Echo Service Examples | ||
|
||
Examples of using the [Echo Service](https://github.com/junjie-w/echo-service) via [Docker image](https://hub.docker.com/r/junjiewu0/echo-service) and [NPM package](https://www.npmjs.com/package/@junjie-wu/echo-service). | ||
Each example runs on a different port to avoid conflicts. | ||
|
||
## 🐳 Docker Usage (Port 3003) | ||
|
||
### Using Container | ||
|
||
```bash | ||
# Start container | ||
npm run start:docker | ||
|
||
# Stop container | ||
npm run docker:stop | ||
``` | ||
|
||
### Using Docker Compose | ||
|
||
```bash | ||
# Start services | ||
npm run compose:up | ||
|
||
# View logs | ||
npm run compose:logs | ||
|
||
# Stop services | ||
npm run compose:down | ||
``` | ||
|
||
## 🎯 CLI Usage (Port 3002) | ||
|
||
Using the package as a command-line tool: | ||
```bash | ||
npm run start:cli | ||
``` | ||
|
||
## 📦 Library Usage (Port 3001) | ||
|
||
Using the package as a library in your code: | ||
```bash | ||
npm run start:lib | ||
``` | ||
|
||
## 🧪 Testing the Examples | ||
|
||
Each example runs on a different port to avoid conflicts. | ||
|
||
### Docker Example (Port 3003) | ||
```bash | ||
curl http://localhost:3003/health | ||
curl http://localhost:3003/echo | ||
``` | ||
|
||
### CLI Example (Port 3002) | ||
```bash | ||
curl http://localhost:3002/health | ||
curl http://localhost:3002/echo | ||
``` | ||
|
||
### Library Example (Port 3001) | ||
```bash | ||
curl http://localhost:3001/health | ||
curl http://localhost:3001/echo | ||
``` | ||
|
||
## ⚠️ Troubleshooting | ||
|
||
### Port Already in Use | ||
If you see "Port in use" error: | ||
```bash | ||
# Check what's using the port | ||
lsof -i :<port_number> | ||
|
||
# Kill the process | ||
kill -9 <PID> | ||
``` | ||
|
||
### Docker on Apple Silicon (M1/M2/M3) | ||
The example automatically handles platform differences, but you can manually run: | ||
```bash | ||
docker run --platform linux/amd64 -p 3003:3000 junjiewu0/echo-service | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "3.8" | ||
services: | ||
echo-service: | ||
image: junjiewu0/echo-service | ||
platform: linux/amd64 | ||
ports: | ||
- "3003:3000" | ||
environment: | ||
- NODE_ENV=production |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "echo-service-examples", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"start:lib": "node src/library-usage.js", | ||
"start:cli": "node src/cli-usage.js", | ||
"start:docker": "node src/docker-usage.js", | ||
"stop:docker": "docker stop echo-service-example && docker rm echo-service-example || true", | ||
"start:docker-compose": "docker compose up -d", | ||
"stop:docker-compose": "docker-compose down", | ||
"logs:docker-compose": "docker compose logs -f" | ||
}, | ||
"dependencies": { | ||
"@junjie-wu/echo-service": "file:../" | ||
} | ||
} |
Oops, something went wrong.