IBM/expressjs-openwhisk

Name: expressjs-openwhisk

Owner: International Business Machines

Description: Apache OpenWhisk Web action redirecting request to Express.js applications

Created: 2017-05-11 20:49:54.0

Updated: 2018-02-22 12:06:17.0

Pushed: 2017-08-30 12:41:10.0

Homepage:

Size: 12

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

This project shows how to deploy new and existing Express.js applications to OpenWhisk. This tutorial takes less then 5 minutes to complete.

Prerequisite

Steps

  1. Create new Express.js application
  2. Change relative paths
  3. Create OpenWhisk action
  4. Deploy application
  5. Test application
1. Create new Express.js application

Open a terminal, and type

m install express-generator -g
press --view=pug myexpressapp
 myexpressapp
m install 

This creates a minimal Express.js application. To check it is working, start the application by typing the command npm start and load http://localhost:3000 in a browser.

2. Change relative paths

The generated Express.s application expects resources to be installed in the domain root folder but by default Apache OpenWhisk web actions are served from a sub-directory.

Change views/layout.pug:

ype html

ad
title= title
if baseurl
  base(href=baseurl)
link(rel='stylesheet', href='stylesheets/style.css')
dy
block content
3. Create OpenWhisk action

Add expressjs-openwhisk module dependency in your project.

m install expressjs-openwhisk --save

Then create the Apache OpenWhisk action handling Web requests by forwarding them to expressjs-openwhisk. Create a file named action.js with this content:

t app = require('./app');
t forward = require('expressjs-openwhisk')(app);

tion main(request) {
turn forward(request);


rts.main = main;

In package.json, add the following entry:


main": "action.js",
..

4. Deploy application

To deploy the application and dependencies on Bluemix, do:

p -r app.zip .
k action update express app.zip --kind nodejs:6 --web raw \
-p baseurl https://openwhisk.ng.bluemix.net/api/v1/web/<org>_<space>/default/express/

Replace <org> and <space> by your Bluemix organization and space, respectively.

5. Test application

And finally test the application by opening https://openwhisk.ng.bluemix.net/api/v1/web/<org>_<space>/default/express in a browser

License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.