Socket
Socket
Sign inDemoInstall

faas-js-runtime

Package Overview
Dependencies
Maintainers
0
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faas-js-runtime - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

5

index.js

@@ -26,3 +26,3 @@ const qs = require('qs');

* Starts the provided Function. If the function is a module, it will be
* inspected for init, shutdown, liveness, and readiness functions and those
* inspected for init, shutdown, cors, liveness, and readiness functions and those
* will be used to configure the server. If it's a function, it will be used

@@ -60,2 +60,5 @@ * directly.

}
if (typeof func.cors === 'function') {
options.cors = func.cors;
}
return __start(func.handle, options);

@@ -62,0 +65,0 @@ }

12

lib/invocation-handler.js

@@ -7,3 +7,4 @@ const invoker = require('./invoker');

fastify.post('/', doPost);
const invokeFunction = invoker(opts.func);
fastify.options('/', doOptions);
const invokeFunction = invoker(opts);

@@ -19,2 +20,11 @@ // TODO: if we know this is a CloudEvent function, should

}
async function doOptions(_request, reply) {
reply.code(204).headers({
'content-type': 'application/json; charset=utf-8',
'access-control-allow-methods': 'OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH',
'access-control-allow-origin': '*',
'access-control-allow-headers': '*'
}).send();
}
done();

@@ -21,0 +31,0 @@ };

@@ -6,3 +6,4 @@ /**

module.exports = function invoker(func) {
module.exports = function invoker(opts) {
const func = opts.func;
return async function invokeFunction(context, log) {

@@ -15,8 +16,15 @@ // Default payload values

'content-type': 'application/json; charset=utf-8',
'access-control-allow-methods':
'OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH',
'access-control-allow-origin': '*'
'access-control-allow-methods': 'OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH',
}
};
if (opts.funcConfig.cors) {
const allowedOrigins = opts.funcConfig.cors();
const requestOrigin = context.headers.origin;
const originIncluded = allowedOrigins.includes(requestOrigin) ? requestOrigin : null;
payload.headers['access-control-allow-origin'] = originIncluded;
} else {
payload.headers['access-control-allow-origin'] = '*';
}
let fnReturn;

@@ -34,3 +42,3 @@ const scope = Object.freeze({});

const message = HTTP.binary(fnReturn);
payload.headers = {...payload.headers, ...message.headers};
payload.headers = { ...payload.headers, ...message.headers };
payload.response = message.body;

@@ -37,0 +45,0 @@ // In this case, where the function is invoked with a CloudEvent

/* eslint-disable no-unused-vars */
import { CloudEvent } from 'cloudevents';
import { IncomingHttpHeaders, IncomingMessage } from 'http';
import { CloudEvent } from 'cloudevents';
import { Http2ServerRequest, Http2ServerResponse } from 'http2';

@@ -19,2 +19,6 @@

// Function that returns an array of CORS origins
// This function is optional.
cors?: () => string[];
// The liveness function, called to check if the server is alive

@@ -21,0 +25,0 @@ // This function is optional and should return 200/OK if the server is alive.

{
"name": "faas-js-runtime",
"version": "2.3.0",
"version": "2.4.0",
"repository": {

@@ -41,3 +41,3 @@ "type": "git",

"fastify": "^4.21.0",
"fastify-raw-body": "^4.2.1",
"fastify-raw-body": "^4.3.0",
"js-yaml": "^4.1.0",

@@ -44,0 +44,0 @@ "node-os-utils": "^1.3.7",

@@ -44,2 +44,6 @@ # Node.js Function Framework

// Function that returns an array of CORS origins
// This function is optional.
cors?: () => string[];
// The liveness function, called to check if the server is alive

@@ -46,0 +50,0 @@ // This function is optional and should return 200/OK if the server is alive.

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc