sasjs / server

Build Apps on Base SAS
https://server.sasjs.io
MIT License
20 stars 3 forks source link

Support JS runtime for services #184

Closed allanbowe closed 2 years ago

allanbowe commented 2 years ago

Currently SASjs Server only supports a SAS runtime for backend services.

This ticket is to enable support for a JS runtime also (and in the future we may also support Python and R).

Why do this?

The number one reason right now is to enable mocked services. By providing a servicename.js alongside a servicename.sas in a solution or application, we can perform integration testing in a non-SAS environment such as a GIT pipeline or on a developer laptop.

From a customer perspective there is also the benefit that a single application may derive inputs from services written in multiple languages. So Python, R, SAS and JS developers can work together on project on the same platform.

How will it be achieved - User Perspective.

Currently, SAS programs are called by reference to a URL parameter (_program) that contains the full path / filename but NOT the extension, eg ?_program=/some/app/services/common/appinit

The proposal is to add a new .env variable (SASJS_RUNTIMES) that will dictate which runtimes are available, and in which order. For instance, if SASJS_RUNTIMES=[SAS,JS] then the executor will first look for appinit.sas and if not found, will run appinit.js.

The developer therefore just needs to add servicename.js files alongside (in the same folder as) their SAS services, to provide the necessary (mocked) response.

How it will be achieved - Technical Perspective

If a .js file is picked up, then - similar to the .sas file - it will be placed in a session folder (code.js) with any URL and session variables inserted, eg:

const _webout="/tmp/saad/sessions/20220601185645-40136-1654109805019/webout.txt";
const _program='/some/app/services/common/appinit';
const _sasjs_username=`allan`;
const _sasjs_tokenfile='/tmp/saad/sessions/20220601185645-40136-1654109805019/reqHeaders.txt';
const sasjs_stpsrv_header_loc='/tmp/saad/sessions/20220601185645-40136-1654109805019/stpsrv_header.txt';

The appinit.js file will contain any logic, update the sasjs_stpsrv_header_loc and return the output to the _webout file.

The NodeJS server will generate the LOG file and package the _webout into the final API response.

Other points

Nice to haves

ghost commented 2 years ago

:tada: This issue has been resolved in version 0.7.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: