Skip to content

Instantly share code, notes, and snippets.

@evanshortiss
Last active October 25, 2017 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanshortiss/00aab1fd0371419a1312e9f4a8ae7d03 to your computer and use it in GitHub Desktop.
Save evanshortiss/00aab1fd0371419a1312e9f4a8ae7d03 to your computer and use it in GitHub Desktop.
A sample application.js file that uses the IP Filter from my previous Gist
'use strict'
const express = require('express')
const cors = require('cors')
const app = express()
// Enable CORS for all requests
app.use(cors())
// Add RHMAP sys middlewares - used to verify application status
app.use('/sys', mbaasExpress.sys(securableEndpoints));
// Add RHMAP mbaas middlewares - these are protected by keys/sessions
app.use('/mbaas', mbaasExpress.mbaas);
// Remove this unless you really need it - causes a perf hit otherwise!
// You should probably namespace it anyways, like under '/assets' or similar
app.use(express.static(__dirname + '/public'));
// All routes after this are only accessible by the IP defined in "lib/ip-filter"
// If an unrecognised IP is detected then a 403 response is returned immediately
app.use(require('./lib/ip-filter'))
// Note: important that this is added just before your own Routes
app.use(mbaasExpress.fhmiddleware());
// Only verified IP addresses can reach me!
app.use('/hello', require('./lib/hello.js')());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment