Skip to content

HTTP API version based routing middleware using rocky + express + http-version

Notifications You must be signed in to change notification settings

h2non/rocky-version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rocky-version

HTTP API version based routing middleware using rocky + express + http-version

Usage

var express = require('express')
var rocky = require('rocky')
var version = require('http-version')

// Configure rocky proxies
var oldAPIProxy = rocky()
oldAPIProxy.forward('http://localhost:3001')
oldAPIProxy.all('/*')

var newAPIProxy = rocky()
newAPIProxy.forward('http://localhost:3002')
newAPIProxy.all('/*')

// create main app
var app = express()

// Configure the middlewares per specific version
app.use(version('1.0', oldAPIProxy.middleware()))
app.use(version('2.0', newAPIProxy.middleware()))

// Start the server
app.listen(3000)

// Test target servers
var oldAPIServer = express()
oldAPIServer.use(function (res, res) {
  res.end('Hello from old API')
})
oldAPIServer.listen(3001)

var newAPIServer = express()
newAPIServer.use(function (res, res) {
  res.end('Hello from new API')
})
newAPIServer.listen(3002)

Test it!

var request = require('supertest')

request('http://localhost:3000')
  .get('/test')
  .set('Version', '1.0')
  .expect(200, 'Hello from old API')
  .end(function (err) {
    if (err) {
      return console.error('Oops:', err)
    }
    console.log('Old API server success')
  })

request('http://localhost:3000')
  .get('/test')
  .set('Version', '2.0')
  .expect(200, 'Hello from new API')
  .end(function (err) {
    if (err) {
      return console.error('Oops:', err)
    }
    console.log('New API server success')
  })

About

HTTP API version based routing middleware using rocky + express + http-version

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy