Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about writing Engine Script Handler in module style. #150

Open
yoh1496 opened this issue Jul 21, 2021 · 0 comments
Open

How about writing Engine Script Handler in module style. #150

yoh1496 opened this issue Jul 21, 2021 · 0 comments

Comments

@yoh1496
Copy link
Contributor

yoh1496 commented Jul 21, 2021

I think it would be nice if I can write Engine Script Handler as module.

For example,

const { something } = require("./submodule");

exports.handler = function(request) {
  const result = something.do();
  return {
    status: 200,
    headers: {"Content-Type": "application/json"},
    body: [ JSON.stringify(result)],
  };
};

Current part of calling function is below.

https://github.com/personium/personium-engine/blob/develop/src/main/java/io/personium/engine/PersoniumEngineContext.java#L367

        Object fObj = scope.get("fn_jsgi", scope);
        Object result = null;
        if (!(fObj instanceof Function)) {
            log.warn("fn_jsgi not found");
            throw new PersoniumEngineException("Server Error", PersoniumEngineException.STATUSCODE_SERVER_ERROR);
        }

        Object[] functionArgs = {jsReq.getRequestObject() };

        previousPhaseTime = System.currentTimeMillis();

        Function f = (Function) fObj;
        result = f.call(cx, scope, scope, functionArgs);

I think this issue could be solved with modifing here with below steps.

  1. load module
  2. call function loadedmodule.handler
  3. return result

Merits

  • Easy to test
    The script which is written in module style can be import easily from local.
  • Free from personium specific rules
    The rule the handle function must be written on first place

Demerits

  • Incompability

How is this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant