text: const express = require('express');
  const app = express();
  const jwt = require('express-jwt');
  const jwtAuthz = require('express-jwt-authz');
  const jwksRsa = require('jwks-rsa');
  const cors = require('cors');
  require('dotenv').config();
  
  if (!process.env.AUTH0_DOMAIN || !process.env.AUTH0_AUDIENCE) {
    throw 'Make sure you have AUTH0_DOMAIN, and AUTH0_AUDIENCE in your .env file'
  }
  
  app.use(cors());
  
  const checkJwt = jwt({
    // Dynamically provide a signing key based on the kid in the header and the singing keys provided by the JWKS endpoint.
    secret: jwksRsa.expressJwtSecret({
      cache: true,
      rateLimit: true,
      jwksRequestsPerMinute: 5,
      jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
    }),
  
    // Validate the audience and the issuer.
    audience: process.env.AUTH0_AUDIENCE,
    issuer: `https://${process.env.AUTH0_DOMAIN}/`,
    algorithms: ['RS256']
  });
  
  const checkScopes = jwtAuthz([ 'read:messages' ]);
  const checkScopesAdmin = jwtAuthz([ 'write:messages' ]);
  
  app.get('/api/public', function(req, res) {
    res.json({ message: "Hello from a public endpoint! You don't need to be authenticated to see this." });
  });
  
  app.get('/api/private', checkJwt, function(req, res) {
    res.json({ message: "Hello from a private endpoint! You need to be authenticated to see this." });
  });
  
  app.get('/api/private-scoped', checkJwt, checkScopes, function(req, res) {
    res.json({ message: "Hello from a private endpoint! You need to be authenticated and have a scope of read:messages to see this." });
  });
  
  app.post('/api/admin', checkJwt, checkScopesAdmin, function(req, res) {
    res.json({ message: "Hello from an admin endpoint! You need to be authenticated and have a scope of write:messages to see this." });
  });
  
  app.listen(3001);
  console.log('Listening on http://localhost:3001');
  