Home

Awesome

Echo-Server / Docker / Kubernetes / Helm

Codecov CodeFactor Grade GitHub stars GitHub issues DockerHub DockerHub

Read the docs : https://ealenn.github.io/Echo-Server

An echo server is a server that replicates the request sent by the client and sends it back.

Available:

docker

<a name='Tableofcontents'></a>Table of contents

<!-- vscode-markdown-toc --> <!-- vscode-markdown-toc-config numbering=false autoSave=true /vscode-markdown-toc-config --> <!-- /vscode-markdown-toc -->

<a name='Configuration'></a>Configuration

EnvironmentHelmCLIDefault
PORTservice.port--port80
LOGS__IGNORE__PINGapplication.logs.ignore.ping--logs:ignore:pingfalse
ENABLE__HOSTapplication.enable.host--enable:hosttrue
ENABLE__HTTPapplication.enable.http--enable:httptrue
ENABLE__REQUESTapplication.enable.request--enable:requesttrue
ENABLE__COOKIESapplication.enable.cookies--enable:cookiestrue
ENABLE__HEADERapplication.enable.header--enable:headertrue
ENABLE__ENVIRONMENTapplication.enable.environment--enable:environmenttrue
ENABLE__FILEapplication.enable.file--enable:filetrue

<a name='UseEcho-Server'></a>Use Echo-Server

curl

I use jq for nice curl results ;)

<a name='Customresponses'></a>Custom responses

QueryHeaderContentConditions
?echo_code=X-ECHO-CODEHTTP code 200, 404200 <= CODE <= 599
404-401 or 200-500-301
?echo_body=X-ECHO-BODYBody message
?echo_env_body=X-ECHO-ENV-BODYThe key of environment variableEnable environment true
?echo_header=X-ECHO-HEADERResponse Header Lang: en-USEnable header true
?echo_time=X-ECHO-TIMEWait time in ms0 <= TIME <= 30.000
?echo_file=X-ECHO-FILEPath of Directory or FileEnable file true

<a name='CustomHTTPStatusCode'></a>Custom HTTP Status Code

➜ curl -I --header 'X-ECHO-CODE: 404' localhost:8080
➜ curl -I localhost:8080/?echo_code=404

HTTP/1.1 404 Not Found
➜ curl -I --header 'X-ECHO-CODE: 404-300' localhost:8080
➜ curl -I localhost:8080/?echo_code=404-300

HTTP/1.1 404 Not Found
HTTP/1.1 300 Multiple Choices
➜ for i in {1..10}
➜ do
➜    curl -I localhost:8080/?echo_code=200-400-500
➜ done

HTTP/1.1 500 Internal Server Error
HTTP/1.1 400 Bad Request
HTTP/1.1 200 OK
HTTP/1.1 500 Internal Server Error
HTTP/1.1 200 OK
HTTP/1.1 500 Internal Server Error

<a name='CustomBody'></a>Custom Body

➜ curl --header 'X-ECHO-BODY: amazing' localhost:8080
➜ curl localhost:8080/?echo_body=amazing

"amazing"

<a name='CustomBodywithEnvironmentvariablevalue'></a>Custom Body with Environment variable value

➜ curl --header 'X-ECHO-ENV-BODY: HOSTNAME' localhost:8080
➜ curl localhost:8080/?echo_env_body=HOSTNAME

"c53a9ed79fa2"
➜ for i in {1..10}
➜ do
➜    curl localhost:8080/?echo_env_body=HOSTNAME
➜ done

"c53a9ed79fa2"
"f10c3af61e40"
"c53a9ed79fa2"
"f10c3af61e40"
"c53a9ed79fa2"

<a name='CustomHeaders'></a>Custom Headers

➜ curl --header 'X-ECHO-HEADER: One:1' localhost:8080
➜ curl localhost:8080/?echo_header=One:1

HTTP/1.1 200 OK
One: 1
➜ curl --header 'X-ECHO-HEADER: One:1, Two:2' localhost:8080
➜ curl "localhost:8080/?echo_header=One:1,%20Two:2"

HTTP/1.1 200 OK
One: 1
Two: 2

<a name='Customresponselatency'></a>Custom response latency

➜ curl --header 'X-ECHO-TIME: 5000' localhost:8080
➜ curl "localhost:8080/?echo_time=5000"

⏳... 5000 ms

You can change default validations with

ENVIRONMENTCLIDefault
CONTROLS__TIMES__MIN--controls:times:min0
CONTROLS__TIMES__MAX--controls:times:max60000

(Latency is defined in milliseconds)

<a name='FileFolderexplorer'></a>File/Folder explorer

➜ curl --header 'X-ECHO-FILE: /' localhost:8080
➜ curl "localhost:8080/?echo_file=/"

["app", "bin", "etc", "usr", "var"]

<a name='Combinecustomactions'></a>Combine custom actions

➜ curl --header 'X-ECHO-CODE: 401' --header 'X-ECHO-BODY: Oups' localhost:8080
➜ curl "localhost:8080/?echo_body=Oups&echo_code=401"

HTTP/1.1 401 Unauthorized
"Oups"

<a name='ChangedefaultQueriesRequestcommands'></a>Change default Queries/Request commands

Read the docs

EnvironmentCLIDefault
COMMANDS__HTTPBODY__QUERY--commands:httpBody:queryecho_body
COMMANDS__HTTPBODY__HEADER--commands:httpBody:headerx-echo-body
COMMANDS__HTTPENVBODY__QUERY--commands:httpEnvBody:queryecho_env_body
COMMANDS__HTTPENVBODY__HEADER--commands:httpEnvBody:headerx-echo-env-body
COMMANDS__HTTPCODE__QUERY--commands:httpCode:queryecho_code
COMMANDS__HTTPCODE__HEADER--commands:httpCode:headerx-echo-code
COMMANDS__HTTPHEADERS__QUERY--commands:httpHeaders:queryecho_header
COMMANDS__HTTPHEADERS__HEADER--commands:httpHeaders:headerx-echo-header
COMMANDS__TIME__QUERY--commands:time:queryecho_time
COMMANDS__TIME__HEADER--commands:time:headerx-echo-time
COMMANDS__FILE__QUERY--commands:file:queryecho_file
COMMANDS__FILE__HEADER--commands:file:headerx-echo-file

<a name='Loggers'></a>Loggers

Read the docs

EnvironmentCLIDefault
LOGS__APP--logs:appecho-server
LOGS__LEVEL--logs:leveldebug
LOGS__FORMAT--logs:formatdefault

<a name='Format'></a>Format

LOG FORMATDESCRIPTION
defaultCombine line & object
lineSimple `Fri, 22 Jan 2021 10:45:20 GMT
objectJSON { "host": {}, http: {}, request: {}}

<a name='Seq'></a>Seq

Full example - Documentation

EnvironmentCLIDefault
LOGS__SEQ__ENABLED--logs:seq:enabledfalse
LOGS__SEQ__SERVER--logs:seq:server
LOGS__SEQ__KEY--logs:seq:key
LOGS__SEQ__LEVEL--logs:seq:levelinfo

<a name='ELK'></a>ELK

Full example - Documentation

<a name='Settingup'></a>Setting up

<a name='Docker'></a>Docker

Read the docs

docker run -p 8080:80 ealen/echo-server

<a name='Docker-Compose'></a>Docker-Compose

Read the docs

Sample

version: "3"
services:
  echo-server:
    image: ealen/echo-server
    ports:
      - 8080:80

With Seq

version: "3"
services:
  echo:
    image: ealen/echo-server
    environment: 
      PORT: 80
      LOGS__SEQ__ENABLED: "true"
      LOGS__SEQ__SERVER: "http://seq:5341"
    ports: 
      - 8080:80

  seq:
    image: datalust/seq
    environment: 
      ACCEPT_EULA: "Y"
    ports:
      - 3010:80

<a name='Kubernetes'></a>Kubernetes

Read the docs

curl -sL https://raw.githubusercontent.com/Ealenn/Echo-Server/master/docs/examples/echo.kube.yaml | kubectl apply -f -

<a name='KuberneteswithHelm'></a>Kubernetes with Helm

Read the docs - Artifact Hub

helm repo add ealenn https://ealenn.github.io/charts
helm repo update
helm install --set ingress.enable=true --name echoserver ealenn/echo-server

<a name='NodeJS'></a>NodeJS

Read the docs

# Dependencies
npm ci
# Run with node
node ./src/webserver --port 8080
# Run with npm script
PORT=8080 npm run start

<a name='Contributing'></a>Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

<a name='Versioning'></a>Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

<a name='License'></a>License

This project is licensed under the GNU Lesser General Public License - see the LICENSE.txt file for details.


<a name='Development'></a>Development

<a name='Documentation'></a>Documentation

Docker-Compose is available on ./docs folder.

docker compose up -d

The documentation is here localhost:4000

<a name='Tests'></a>Tests

npm ci
# Without code coverage
npm run test
# With code coverage
npm run test-with-coverage

<a name='Releasenotes'></a>Release notes

git log --pretty=oneline

<a name='UpdateHelmChart'></a>Update Helm Chart

=> https://github.com/Ealenn/charts/tree/master/charts/echo-server