This seed app provides a quick start for building a React web app on Viya, SAS EBI or Foundation SAS with the SASjs DevOps framework.
It is deliberately small: plain React and plain CSS, with no UI component library, so the only thing to keep up to date with is React itself. What it demonstrates is the SASjs side - a request, an upload, a session, and a SAS logs panel that reads the log a request came back with.
Three services come with it, in sasjs/services:
common/appinit- the list of areas the data page offers, called once at start-up;common/getdata- the springs for one area, with the selection sent as a table;files/upload- copies an uploaded file into a folder on the server and answers with a directory listing, or aborts with the reason it could not write.
Install the pre-commit framework, then run npm run prepare to enable both .git-hooks/pre-commit and the existing commit-message hook. The repository's .npmrc sets ignore-scripts=true, so npm ci does not activate hooks automatically. The pre-commit wrapper runs the pinned Gitleaks configuration against staged changes and blocks commits if the framework is missing. First use needs network access and Go (pre-commit 3+ can bootstrap Go). Before enabling hooks, inspect git config --get core.hooksPath and preserve any existing custom hooks; npm run prepare changes that setting. Local hooks can be bypassed with --no-verify. CI separately scans committed history on pull requests and pushes to main; make that check required in branch protection to enforce it before merging.
Clone the repo, cd into it, and npm install.
Next, update the <sasjs> element in src/index.html:
appLoc- the folder (eg in metadata or SAS Drive) under which the SAS services are created.serverType- either SAS9, SASVIYA or SASJS.serverUrl- only relevant if not serving from the SAS domain (!SASCONFIG/LevX/Web/WebServer/htdocsin SAS9 or/var/www/htmlon SAS Viya).loginMechanism-Defaultfor user/password,Redirectedfor SSO. See the SAS Logon section of the adapter documentation.debug- when true, every request keeps a log, which is what the SAS Logs panel shows.useComputeApi- Viya only; whether the adapter goes through the Compute API.contextName- only relevant whenuseComputeApiis true.
Then:
npm start # webpack dev server on http://localhost:3000
npm run build # production build in build/More detail on every setting is in the @sasjs/adapter
documentation. If you are running
locally you will either need to whitelist localhost on the server, or enable
CORS as described here.
The app also builds as a mock site: the same frontend, with a browser-hosted backend standing in for SAS, so it can be opened with no licence, no server and no deployment.
npm run mock:build # frontend + services + the browser host
npm run mock:start # serves sasjsbuild/mock on http://127.0.0.1:3001What makes that work is sasjs/mocks/: a JavaScript twin of each service
(common/appinit, common/getdata, files/upload) answering the same webout
the SAS service does. The upload twin refuses a folder that is not on the drive,
as %mp_abort does, so the abort dialog is demonstrable too. Each twin also
reports a log - the fixture in sasjs/mocks/services/common/mock-sas-log.json,
the failure-shaped one half the time and a clean one the rest - so the SAS Logs
panel has something to show on a site with no SAS behind it. The twins read
springs.json, which is generated from the datalines block in
serviceinit.sas, so the demo shows the rows the deployed service would return.
npm run check:data fails when the two drift apart, and npm run test:mock
boots the built worker and asserts that each service answers.
This is also what https://sasjs.github.io/react-seed-app/ serves.
The best way to deploy SAS services is using the SASjs CLI.
Simply install, update the defaultTarget
attribute in the sasjsconfig.json file, and run:
sasjs auth # be sure to use the same serverType and appLoc as above
sasjs cbdThis authenticates to your target (follow the prompts) and then compiles, builds
and deploys the services. With streamWeb: true in the target's streamConfig
it also deploys your frontend as a streaming
app (no need for a web server).
If you are looking to build quickly and do not have time to install NPM, you can create the web services on SAS9 or SASVIYA with the code below.
%let appLoc=/Public/app/react-seed-app; /* SAS Folders App Location */
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;
filename ft15f001 temp;
parmcards4;
proc sql;
create table areas as select distinct area from sashelp.springs;
%webout(OPEN)
%webout(OBJ,areas)
%webout(CLOSE)
;;;;
%mx_createwebservice(path=&appLoc/services/common, name=appinit)
parmcards4;
%webout(FETCH)
proc sql;
create table springs as select * from sashelp.springs
where area in (select area from areas);
%webout(OPEN)
%webout(OBJ,springs)
%webout(CLOSE)
;;;;
%mx_createwebservice(path=&appLoc/services/common, name=getdata)- The app reads its configuration from the
<sasjs>element insrc/index.html. Every target insasjs/sasjsconfig.jsonrewrites that element, which is how one codebase serves Viya, SAS 9, a SASjs Server and the mock build. - There is no UI component library. The shell - header, sign-in, SAS logs panel
- is plain React, and every colour comes from the tokens in
src/styles.scss, so light and dark are one set of values rather than two stylesheets. The choice is applied before the first paint bypublic/theme-init.js.
- is plain React, and every colour comes from the tokens in
- The SAS logs panel counts errors, warnings and notable notes with
parseLogfrom@sasjs/utils, the parser Data Controller uses, so the counts agree with that app's. Clicking a message scrolls the log to the line it names. npm testruns Vitest over the pure functions - the log summary, the abort payload and the timestamp formatting.npm run lintis Prettier.- The Documentation menu item opens
docs/index.html, which the build copies from thepublic/docssubmodule. Rungit submodule update --init public/docsin a fresh clone.
A service can be written in JavaScript instead of SAS - the browser mock build
runs them, and a SASjs Server target can be deployed with them. They live in
sasjs/mocks, mirroring the service tree (sasjs/mocks/services/common/appinit.js
is the twin of sasjs/services/common/appinit.sas), and the CLI copies them into
the build through the syncFolder setting in sasjs/sasjsconfig.json.
A JavaScript service is called with the same inputs the SAS one receives: the
uploaded tables as _WEBIN_NAME<n> / _WEBIN_FILEREF<n>, the request parameters
as consts, and the webout() block to answer with (webout('OPEN'),
webout('OBJ', 'name', rows), webout('CLOSE')). webout('FETCH') returns
input tables, while _WEBIN_FILEREF<n> names the staged file: read its bytes with
fs.readFileSync. These mocks use the host's shared prelude: build the browser
site with CLI 8.0.3 or later for the corrected trailing-CRLF and blank-record
handling. Server 8.0.0 supports staged paths but still embeds utils 4.13.0 and
lacks those FETCH fixes; a Server release containing utils 4.13.2 is required for
parity. The seed pins adapter 6.1.2 and app utils 4.13.2; installing utils in the
app alone does not update either host's runtime. The service harness exercises the
installed utils prelude with both server- and browser-shaped inputs, but is not
a substitute for running against a released Server host.
If such a service requires a third-party package, bundle it before deploying to a SASjs Server target, which does not install dependencies for you.
This app works on all versions of SAS Viya, in SAS 9 EBI from 9.3 and above, and on regular Foundation SAS (or WPS) installs using SASjs Server.
It does not work on SAS University Edition.
This project uses Prettier to format code. Install the 'Prettier - Code formatter' extension for VS Code; files you are editing are formatted on save.
Thanks goes to these wonderful people (emoji key):
Allan Bowe 💻 |
Yury Shkoda 💻 |
Krishna Acondy 💻 |
Muhammad Saad 💻 |
Sabir Hassan 💻 |
Mihajlo Medjedovic 💻 |
Vladislav Parhomchik |
This project follows the all-contributors specification. Contributions of any kind welcome!