A template for creating node microservices with:
- express route handling
- get/post REST api routes
- WebSocket api routes
- http admin UI routes
- JWT auth
- docker support
See: A Nodejs Microservice Template
For an example customization of this template, see:
- Using Microsoft Orchestrator for Intent Recognition and Dispatch to Luis
- https://github.com/wwlib/orchestrator-microservice
npm install
npm run build
npm run start
docker build -t microservice-template .
- or
npm run docker:build
Copy .env-example
to .env
SERVER_PORT=8000
USE_AUTH=true
docker run -it --rm -p 8000:8000 --env-file ./.env microservice-template
- or
npm run docker:run
Without auth:
curl --location --request POST 'http://localhost:8000/post' \
--header 'Content-Type: application/json' \
--data-raw '{
"utterance": "hello"
}'
With auth
curl --location --request POST 'http://localhost:8000/post' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJ1c2VyMSIsImF1dGgiOnsicGVybWlzc2lvbnMiOlt7InNjb3BlcyI6WyJyZWFkIl0sInJlc291cmNlIjoiZXhhbXBsZSJ9XX0sImlhdCI6MTY1MzM2MTQ3OX0.WMbG7o7CaKOf6H7djUpZ7aylvUeYw3N8cdn1K1FrN8A' \
--data-raw '{
"utterance": "hello"
}'
{"status":"OK","utterance":"hello","accountId":"account1"}
curl --location --request POST 'http://localhost:8000/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
"accountId": "account1",
"password": "12345!"
}'
{"message":"Logged in successfully.","access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJ1c2VyMSIsImF1dGgiOnsicGVybWlzc2lvbnMiOlt7InNjb3BlcyI6WyJyZWFkIl0sInJlc291cmNlIjoiZXhhbXBsZSJ9XX0sImlhdCI6MTY1NDM2NzQ5NSwiZXhwIjoxNjU0MzY3NTU1fQ.J7yxsSoOYTvNQtMkLrmlY_TEZT6x4jEvYvnI_Gqr64Q","refresh_toke":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJ1c2VyMSIsImlhdCI6MTY1NDM2NzQ5NSwiZXhwIjoxNjU0NDUzODk1fQ.Lj7fairF_ABjeXzIc_-38aMqfj3ce08fd33V3ymoa04","account_id":"account1"}
cd tools
node socket-cli.js
Note; The socket client will authenticate using the credentials in the tools/.env
file.
This will start a REPL that will accept and echo prompts.
client connected
ctrl-c to quit
> hello
hello
Anything typed at the >
prompt will be echoed.