Code Monkey home page Code Monkey logo

serverless-scripting-examples's People

Contributors

bgabler avatar cretz avatar dependabot[bot] avatar klaude avatar scotwells avatar stackpathtladd2 avatar thril avatar tladd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

serverless-scripting-examples's Issues

wasm-rust example crashes

Describe the bug
I'm trying to run wasm-rust. It works on my local but crashes on stackpath. When I debug it on your serverless sandbox, I saw error message below.

[error] Error: An object was thrown from supplied code within isolated-vm, but that object was not an instance of `Error`.
    at Object.dispatchSync (dist/v8env.js:15:53154)
    at t.TextDecoder.decode (dist/v8env.js:23:59534)
    at Module.<anonymous> (<script>:1:3840)
    at Module.<anonymous> (<script>:1:8353)
    at t (<script>:1:110)
    at Module.<anonymous> (<script>:1:781753)
    at t (<script>:1:110)
    at <script>:1:902
    at <script>:1:911

To reproduce
I didn't make any change. Just build and deploy it. Or try it in serverless sandbox

Expected behavior
On my local it returns resized image. I was expecting same on stackpath.

Actual behavior
Instead I'm getting server error.

"wasm-c" example run into exception

I've tried to run the "wasm-c" example from repository following instructions, I've compiled and deployed, but on production I get "Critical error.".

I've so tried to compile it without optimization (for debug scope) and run it on https://sandbox.edgeengine.io/, but I receive this error:

Error: TypeError: instance._fib is not a function
    at handleRequest (<script>:631:39)
    at addEventListener (<script>:635:21)
    at t.fireFetchEvent (webpack:///src/events.ts:160:1)
    at fetchCallback (/v8-scriptengine/packages/v8-scriptengine/build/server.js:110:31)

cache in jwt-validation project does not work

Is this a security issue?
No

Is this an issue with your StackPath account or service?
No

Before continuing
OK

Describe the bug
I have went through the jwt-validation project. I try to use cache in the same way as in the getJWK.js and I quickly realize that Serverless scripts live and die per request; the code is not continuously running in the background. the cache = {} will never store anything.

To reproduce

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// CONCATENATED MODULE: ./src/requestHandler.js

const cache = {};

/**
 * Handle the HTTP request for the script
 *
 * This handler will validate that the authorization token provided by the user is a valid JWT
 * that was signed by the authorization server. This validation is done by the TokenValidator
 * that was created above. If the token is valid, the request is fetched and the response is
 * returned to the client. If the token is invalid, a 401 error will be returned back to the client
 *
 * @param {Request} request
 * @returns {Response}
 */
function buildRequestHandler() {
  return async function handleRequest(request) {
    try {
      // Now that we've validated that the user has provided a valid JWT that our authorization
      // server provided we can continue processing the user's request
      const response = await fetch(request);
      console.log('cache',cache);
      if(Object.entries(cache).length === 0){
        cache['item']= 'test item';
        console.log('assigned cache');
      }
      // Modify the request here if necessary

      return response;
    } catch (e) {
      // TODO: add proper error handling
      return new Response(e.stack || e, {
        status: 500,
      });
    }
  };
}

// CONCATENATED MODULE: ./src/index.js



// Create the handler for our requests and inject the JWT validator we built
const handleRequest = buildRequestHandler();

// Register the request handler with StackPath's serverless scripting platform
//
// eslint-disable-next-line no-restricted-globals
addEventListener('fetch', (event) => {
  event.respondWith(handleRequest(event.request));
});


/***/ })
/******/ ]);

Expected behavior
The console.log('cache', cache); should display the 'test item', but instead it is empty object per request

Actual behavior
There should be a way to use cache, I haven't found a way to do it and the cache used in example is pretty misleading. cloudflare worker does provide cache API for serverless function, which is unavailable in stackpath

System Details (please complete the following information):
N/A

Additional context
N/A

Add an example on how to use stream transformation with backpressure control

I'd like to see an example on how to create a working script that permits to handle a stream transformation, for example taking from the body of the fetched response, and returning transformed as result.

More specifically, I'd like to see how to handle also large streams, implementing so a backpressure control that permits to not incur into memory overflow errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.