Skip to content
Deva Kumar edited this page Apr 27, 2022 · 3 revisions

Custom routes

obsolete viya-appserverjs routes can be extended with custom routes. Create a new entry (app.js) and start the server with the following command

node app --env=overrides.env --docker=Dockerfile --appenv=appenv.js

Sample app.js

let restafServer = require('@sassoftware/viya-appserverjs');

let customRoutes = getCustomRoutes();
restafServer.icli(customRoutes)

function getCustomRoutes() {
  ... define routes following the documentation in hapijs
  ... https://hapi.dev/api/?v=19.1.1
};

Example

let restafServer = require('@sassoftware/viya-appserverjs');

let customRoutes = getCustomRoutes();
restafServer.icli(customRoutes)

function getCustomRoutes () {
    let handler = [
    {
            method: ['GET'],
            path  : `/getDB`,
            config: {
                auth   : false,
                cors   : true,
                handler: getDB
            }
        },
        {
            method: [ 'POST' ],
            path: `/updateDB`,
            config: {
                auth: false,
                cors: true,
                handler: updateDB
            }
        }
    ];
    return handler;
}

async function getDB (req, h) {
    return 'in getDB';
}

async function updateDB (req, h) {
    return 'in updateDB';
}
Clone this wiki locally