Skip to content
Deva Kumar edited this page May 24, 2020 · 13 revisions

Introduction

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:

  1. Supports authentication using authorization_code and implicit flow.
  2. Supports serving up static content
  3. Can be extended with custom routes
  4. Supports TLS

Basic Steps

  1. Build your app
  2. Obtain a clientid and clientsecret - see Managing clientids for instructions on how to obtain this.
  3. Configure the server using a combination of environment variables, env files and Dockerfile
  4. Start the server with a simple command
npx @sassoftware/restaf-server  --env=your-env-envfile --docker=your-Dockerfile --appenv=your-appenv.js-file

Quick start example

Let us assume that your application directory structure is:

  appdir/
    public/
      index.html
    override.env
    Dockerfile
    appenv.js
    package.json

Envfile

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

Dockerfile

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;
        };
Clone this wiki locally