-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (29 loc) · 838 Bytes
/
server.js
File metadata and controls
36 lines (29 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const express = require("express");
require("dotenv").config();
var jwt = require("express-jwt");
var jwksRsa = require("jwks-rsa");
const checkJwt = jwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://${process.env.REACT_APP_AUTH0_DOMAIN}/.well-known/jwks.json`,
}),
audience: process.env.REACT_APP_AUTH0_AUDIENCE,
issuer: `https://${process.env.REACT_APP_AUTH0_DOMAIN}/`,
algorithms: ["RS256"],
});
const app = express();
// app.use(checkJwt);
app.get("/public", function (req, res) {
res.json({
message: "Hello from a public API",
});
});
app.get("/private", checkJwt, function (req, res) {
res.json({
message: "Hello from a private API",
});
});
app.listen(3001);
console.log("API Server listening on port: " + process.env.REACT_APP_API_URL);