This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __addSecureAndCacheHeaders(res) { | |
// OWASP Secure Headers | |
res.set('X-Content-Type-Options', 'nosniff') | |
res.set('X-XSS-Protection', '1; mode=block') | |
res.set('X-Frame-Options', 'DENY') | |
res.set('Strict-Transport-Security', 'max-age=63072000; includeSubDomains') | |
// Avoid Caching Tokens | |
res.set('Cache-Control', 'no-cache, no-store, must-revalidate') | |
res.set('Pragma', 'no-cache') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
axios({ | |
method: method, | |
baseURL: service.base_url + ':' + service.port, | |
url: request.path, | |
responseType: 'json', | |
data: request.body, | |
params: request.params, | |
headers: { | |
gateway_signature: token, | |
authorization: request.authorization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __generateGatewaySignature(serviceSecretKey, callback) { | |
jwt.sign({ | |
gateway: 'ORION_GATEWAY', | |
gateway_secret: SECRET_KEY, | |
}, serviceSecretKey, { expiresIn: 1800000 }, callback) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__getServiceInformation(request.app_id || '') | |
.then(service => { | |
let flag = false | |
const availableEndPoints = service.endpoints[request.method.toLowerCase()] || [] | |
const splittedRequestPath = request.path.replace(/^\/|\/$/g, '').split('/') | |
for ( let i = 0; i < availableEndPoints.length; i++ ) { | |
let splittedEndPointPath = availableEndPoints[i].replace(/^\/|\/$/g, '').split('/') | |
if ( splittedRequestPath.length === splittedEndPointPath.length ) { | |
let fractalCheckFlag = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
firstService: | |
port: 3422 | |
base_url: http://localhost | |
endpoints: | |
get: | |
- /user | |
- /item | |
- /testing | |
put: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __grabRequest(req) { | |
// We need the consume IP Address for collecting a log for our Gateway | |
const ipAddress = (req.headers['x-forwarded-for'] || '').split(',').pop() || | |
req.connection.remoteAddress || | |
req.socket.remoteAddress || | |
req.connection.socket.remoteAddress | |
const apiSignatureKey = req.headers['basic_auth'] || '' // Basic Auth for consumer. | |
return { | |
ip_address: ipAddress, | |
basic_auth: apiSignatureKey, |