Example Docker application using Moesif OpenResty plugin to log API calls to Moesif API analytics
To learn more about configuration options, please refer to Moesif OpenResty plugin.
- Clone this repo and edit the
nginx.conf.d/main.conf
file to set your actual Moesif Application Id.
Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.
You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top right menu, and then clicking API Keys.
- Build the docker image
docker build --no-cache -t nginx-docker-demo ./
- Start the docker container:
docker-compose up -d
By default, The container is listening on port 8000. You should now be able to make a simple GET
request:
curl -X GET http://localhost:8000
- The data should be captured in the corresponding Moesif account.
Congratulations! If everything was done correctly, Moesif should now be tracking all network requests that match the route you specified earlier. If you have any issues with set up, please reach out to support@moesif.com.
The demo contains an example JWT verification script that allows you to authorize requests to the /api
endpoint. To see how it works, follow these steps:
- Specify your JWT secret in the
main.conf
file. - Include your JWT token in the
Authorization
header of your HTTP request:
curl -X POST -H "Content-Type: application/json" "Authorization: YOUR_JWT_TOKEN" -d '{"name":"moesif"}' "http://localhost:8000/api?x=2&y=4" -H 'User-Id:123' -H "Company-Id:567"
The server sends a valid response back:
{
"message": "Hello World",
"completed": true
}
Without a valid JWT token, the server sends a 401 Unauthorized
error response.