-
Notifications
You must be signed in to change notification settings - Fork 2
Home
restaf-server is an app server designed for rapid development and deployment of SAS Viya applications. restaf-server uses hapijs to do all the heavy lifting.restaf-server takes advantage of the great configurabilty of hapijs.
The key features are:
- Supports authentication using authorization_code and implicit flow.
- Supports serving up static content
- Can be extended with custom routes
- Supports TLS
- Build your app
- Obtain a clientid and clientsecret - see Managing clientids for instructions on how to obtain this.
- Configure the server using a combination of environment variables, env files and Dockerfile
- Start the server with a simple command
npx @sassoftware/restaf-server --env=your-env-envfile --docker=your-Dockerfile --appenv=your-appenv.js-file
Let us assume that your application directory structure is:
appdir/
public/
index.html
override.env
Dockerfile
appenv.js
package.json
VIYA_SERVER=http://your-viya-server
# OAUTHFLOW - clientid - code|implicit
AUTHFLOW=code
# Get these from your administrator
CLIENTID=appc
CLIENTSECRET=secret
# Where the app server is running:
# Valid values:
# localhost
# http(s)://hostname
# http(s)://ip address
# When running in docker do not specify this.
APPHOST=localhost
# PORT for app server
APPPORT=8080
# APPNAME - The appserver will start at {APPHOST}:{APPPORT}/{APPNAME}
APPNAME=viyaapp
# Location of assets
# all assets are located relative to APPLOC
APPLOC=./public
# Main entry of your app
# On successful authentication this entry will be displayed in the browser
APPENTRY=index.html
# The js object returned from APPENV will be available as APPENV js variable in your js
APPENV=appenv.js
# TLS Support
# see section on TLS Support for these options
A typical Dockerfile looks as follows
FROM node:12.16.1-alpine
LABEL maintainer="your-email"
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
ENV APPHOST=0.0.0.0
ENV SAMESITE=None,false
ENV KEEPALIVE=YES
# You can specify the values in env file here
# Caution: DO not specify anything that might be a security violation(ex: your viya server)
Build a placeholder appenv.js file with this content
let x= {hi: 'hi there'};
return x;
You then start the server with the following command
npx @sassoftware/restaf-server --env=./override.env --docker=./Dockerfile --appenv=./appenv.js
The server will start at http://localhost:8080/viyaapp (http:{APPHOST}:{APPPORT}/APPNAME).
When you visit this link you will be prompted for userid and password. On successful authentication the html listed for APPENTRY(index.html in this example) will be displayed in an authenticated browser session.
From your html you can make API calls to Viya. Below is sample javascript to get the root links for the files service using axios.(Note: host is the url for the Viya server).
async function makeViyaCall () {
let config = {
url : host + '/files/',
method : 'GET',
withCredentials: true,
headers : {
'accept': 'application/json, application/vnd.sas.api+json',
}
};
let r = await axios(config);
return r.data;
};
If you are using implicit flow, then make the following changes to the quick start example.
In the env file:
AUTHFLOW=implicit
CLIENTSECRET=
CLIENTID= <your implicit flow clientid>
In your index.html parse the url to obtain the token and Viya host url. Below is a simple example of parsing the url.
function parseUrl(){
let hash = window.location.hash;
let qa = hash.split('&');
return {
tokenType: qa[0].split('=')[1],
token : qa[1].split('=')[1],
host : window.location.search.split('=')[1]
}
}