UNPKG

jetstream-microservice

Version:

Jetstream Node Package for easy implementation of Jetstream microservices

1 lines 743 B
var jwt=require("jsonwebtoken");module.exports={inbound:function(e,t,o){if(self=this,e.headers["x-jetstream-jwt"]){var r=e.headers["x-jetstream-jwt"];jwt.verify(r,jetstreamConfig.jwt_secret,{issuer:jetstreamConfig.registry_url,audience:jetstreamConfig.location},function(e,s){s?o():(t.status(401).send("Unauthorized"),console.log("Error: "+e),console.log("Token: "+r),console.log("Expected registry: "+jetstreamConfig.registry_url),console.log("Expected audience: "+jetstreamConfig.location))})}else t.status(401).send("Unauthorized"),console.log("Unauthorized: No header")},outbound:function(){return jwt.sign({},jetstreamConfig.jwt_secret,{issuer:jetstreamConfig.location,audience:jetstreamConfig.registry_url,expiresIn:5,noTimestamp:!1})}};