Miro

node v10.23.3
version: 3.0.0
endpointsharetweet
const jwt = require("jsonwebtoken") const { json, send } = require("micro") const query = require("micro-query") const uuid4 = require("uuid4") function getJWT() { const issuer = process.env.MIRO_ACCESS_TOKEN; const secret = process.env.MIRO_SECRET; return jwt.sign( { iss: issuer }, secret, { algorithm: "HMAC256", expiresIn: "24h", issuer: issuer, jwtid: uuid4() } ) } const apiHandlers = { token: () => { return { token: getJWT() } } } exports.endpoint = async (req, res) => { res.setHeader("Access-Control-Allow-Origin", "*") res.setHeader("Access-Control-Allow-Methods", "*") console.log(req); json(req).then(async () => { const { api } = query(req) console.log(api); const response = await apiHandlers[api]() send(res, 200, response) }).catch(error => { console.log(error); send(res, 400, {error}) }) }
Loading…

no comments

    sign in to comment