airbits-http-utils
Advanced tools
Comparing version 1.0.3 to 1.0.4
30
index.js
@@ -12,2 +12,14 @@ var jwt = require("jsonwebtoken"); | ||
this.generateOKResponseForLogin = (req, token, body) => { | ||
const origin = filterOrigins(req.headers.origin); | ||
var d = new Date(); | ||
d.setTime(d.getTime() + 100*24*60*60*1000); | ||
const expires = "expires="+ d.toUTCString()+ ";"; | ||
const cookie = "xens-session="+loginResult.token+ "; Domain=api.beta.xens.io; Path=/; "+expires; | ||
return buildLoginResponse(origin, cookie, body); | ||
} | ||
this.generateErrResponse = (req) =>{ | ||
@@ -24,4 +36,17 @@ const origin = filterOrigins(req.headers.origin); | ||
function buildLoginResponse(origin, coookie, body){ | ||
return { | ||
"headers": { | ||
"Access-Control-Allow-Origin" : origin, // Required for CORS support to work | ||
"Access-Control-Allow-Credentials" : true, | ||
"Access-Control-Allow-Headers": "Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token", | ||
"Access-Control-Allow-Methods": "DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT", | ||
"Set-Cookie": coookie | ||
}, | ||
"statusCode": 200, | ||
"body": JSON.stringify(body) | ||
} | ||
} | ||
function buildResponse(origin, statusCode, body){ | ||
@@ -55,3 +80,4 @@ return { | ||
let parts = rawCookies.split("; " + name + "="); | ||
if (parts.length == 2) return parts.pop().split(";").shift(); | ||
if (parts.length | ||
=== 2) return parts.pop().split(";").shift(); | ||
} | ||
@@ -58,0 +84,0 @@ |
{ | ||
"name": "airbits-http-utils", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "http utilitities for xens project", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3031
60