Skip to content

Moesif/nginx-docker-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenResty with Moesif API Logging Example

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.

How to run this example

  1. 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.

  1. Build the docker image
docker build --no-cache -t nginx-docker-demo ./
  1. 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
  1. 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.

JWT verification

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:

  1. Specify your JWT secret in the main.conf file.
  2. 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.

About

Nginx Resty Moesif Example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published