Skip to content

Commit

Permalink
Merge pull request #37 from junjie-w/develop
Browse files Browse the repository at this point in the history
Merge Develop Branch into Main
  • Loading branch information
junjie-w authored Nov 19, 2024
2 parents 0201362 + 7ab9c67 commit 2e3fd54
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 490 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Security audit
run: npm audit

- name: Run linting
run: npm run lint

Expand Down
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ npm install @junjie-wu/echo-service
docker pull junjiewu0/echo-service
docker run -p 3000:3000 junjiewu0/echo-service

# For ARM-based machines (Apple Silicon, etc.)
docker pull --platform linux/amd64 junjiewu0/echo-service
docker run --platform linux/amd64 -p 3000:3000 junjiewu0/echo-service

# Using Docker Compose
docker compose up -d

# Building Locally
# Build and Run Locally
docker build -t echo-service .
docker run -p 3000:3000 echo-service
```
Expand All @@ -56,17 +60,22 @@ import { createServer } from '@junjie-wu/echo-service';
const server = createServer(3000);
```

### 🧪 Test the Service
### 🧪 Try it out

```bash
# Check service health
http://localhost:3000/health
curl http://localhost:3000/health

# Echo back request details
http://localhost:3000/echo
curl http://localhost:3000/echo

# Echo with query parameters
curl "http://localhost:3000/echo?name=test"

# Supports all HTTP methods and parameters
http://localhost:3000/echo?name=test
# Echo with POST data
curl -X POST -H "Content-Type: application/json" \
-d '{"message": "hello"}' \
http://localhost:3000/echo
```

### 📋 Examples
Expand Down Expand Up @@ -94,15 +103,21 @@ npm run start:lib # Library usage

### Setup

1. Clone the repository:
```bash
git clone https://github.com/junjie-w/echo-service.git
cd echo-service
```

2. Install dependencies:
```bash
# Install dependencies
npm install

# Start development server
npm run dev

# Run tests
npm test

# Build for production
npm run build

# Start production server
npm start
```

### Commit Convention
Expand Down
20 changes: 11 additions & 9 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# 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)
## 🐳 Docker Usage

### Using Container

Expand All @@ -12,30 +11,30 @@ Each example runs on a different port to avoid conflicts.
npm run start:docker

# Stop container
npm run docker:stop
npm run stop:docker
```

### Using Docker Compose

```bash
# Start services
npm run compose:up
npm run start:docker-compose

# View logs
npm run compose:logs
npm run logs:docker-compose

# Stop services
npm run compose:down
npm run stop:docker-compose
```

## 🎯 CLI Usage (Port 3002)
## 🎯 CLI Usage

Using the package as a command-line tool:
```bash
npm run start:cli
```

## 📦 Library Usage (Port 3001)
## 📦 Library Usage

Using the package as a library in your code:
```bash
Expand Down Expand Up @@ -67,6 +66,7 @@ curl http://localhost:3001/echo
## ⚠️ Troubleshooting

### Port Already in Use

If you see "Port in use" error:
```bash
# Check what's using the port
Expand All @@ -76,8 +76,10 @@ lsof -i :<port_number>
kill -9 <PID>
```

### Docker on Apple Silicon (M1/M2/M3)
### Docker on ARM-based machines (Apple Silicon, etc.)

The example automatically handles platform differences, but you can manually run:
```bash
docker pull --platform linux/amd64 junjiewu0/echo-service
docker run --platform linux/amd64 -p 3003:3000 junjiewu0/echo-service
```
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"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",
"stop:docker-compose": "docker compose down",
"logs:docker-compose": "docker compose logs -f"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/docker-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ docker rm ${CONTAINER_NAME}
Troubleshooting:
1. Make sure Docker is running
2. Check if port ${DOCKER_PORT} is available
3. For Apple Silicon Macs (M1/M2/M3), try manually:
3. For ARM-based machines (Apple Silicon, etc.), try manually:
docker pull --platform linux/amd64 ${IMAGE_NAME}:${IMAGE_TAG}
docker run --platform linux/amd64 -p ${DOCKER_PORT}:3000 ${IMAGE_NAME}:${IMAGE_TAG}
Expand Down
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ export default {
{
displayName: '🧪 UNIT',
...baseConfig,
testMatch: ['<rootDir>/src/tests/unit/**/*.test.ts'],
testMatch: ['<rootDir>/src/__tests__/unit/**/*.test.ts'],
rootDir: '.'
},
{
displayName: '🔄 INTEGRATION',
...baseConfig,
testMatch: ['<rootDir>/src/tests/integration/**/*.test.ts'],
testMatch: ['<rootDir>/src/__tests__/integration/**/*.test.ts'],
rootDir: '.'
},
{
displayName: '🌐 API',
...baseConfig,
testMatch: ['<rootDir>/src/tests/api/**/*.test.ts'],
testMatch: ['<rootDir>/src/__tests__/api/**/*.test.ts'],
rootDir: '.'
}
],
Expand All @@ -44,7 +44,7 @@ export default {
},
collectCoverageFrom: [
'src/**/*.{ts,js}',
'!src/tests/**',
'!src/__tests__/**',
'!src/**/*.d.ts',
'!src/types/**',
'!src/server.ts',
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ help() {
# Main execution
main() {
command="$1"
shift # Remove the first argument
shift
if [[ " ${allowed_targets[@]} " =~ " ${command} " ]]; then
$command "$@"
else
Expand Down
69 changes: 40 additions & 29 deletions scripts/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,44 @@ Echo Service Commands
Development
----------
npm run dev # Start development server
npm start # Start production server
Docker
------
npm run docker:build # Build Docker image
npm run docker:start # Start Docker container
npm run docker:stop # Stop Docker container
Package Development
-----------------
npm run cli # Run CLI locally
npm run link # Link package globally
npm run unlink # Unlink @junjie-wu/echo-service globally
Global Usage
-----------
# Install globally
npm install -g @junjie-wu/echo-service
# Run anywhere
echo-service
# Or use npx without installing
npx @junjie-wu/echo-service
Environment Variables
-------------------
PORT # Specify port (default: 3000)
npm run dev # Start development server with auto-reload (tsx watch)
npm run build # Build TypeScript project
npm start # Start production server
npm run prepare # Setup Husky git hooks
Testing
-------
npm test # Run all tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Generate test coverage report
npm run test:ci # Run tests in CI mode with coverage
npm run test:unit # Run unit tests only
npm run test:integration # Run integration tests only
npm run test:api # Run API tests only
npm run start:test # Start test server
npm run stop:test # Stop test server
Linting
-------
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint issues automatically
Docker Operations
---------------
npm run docker:build # Build Docker image
npm run docker:start # Start Docker container
npm run docker:stop # Stop Docker container
npm run docker:logs # View container logs
npm run docker:clean # Remove container and image
npm run docker:shell # Open a shell in the container
npm run docker:info # Show container information
npm run docker:restart # Restart Docker container
npm run docker:help # Show all Docker commands
CLI Development & Usage
-----------------------
npm run cli # Run CLI locally from dist/
npm run link # Link package globally
npm run unlink # Unlink package globally
npx @junjie-wu/echo-service # Run CLI without installing
"
Loading

0 comments on commit 2e3fd54

Please sign in to comment.