Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-gateway

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-gateway - npm Package Compare versions

Comparing version 1.5.1 to 1.5.2

demos/basic-express.js

14

demos/basic.js

@@ -12,3 +12,3 @@ const gateway = require('./../index')

prefix: '/public',
target: 'http://public.myapp:300',
target: 'http://localhost:3000',
docs: {

@@ -21,3 +21,3 @@ name: 'Public Service',

prefix: '/admin',
target: 'http://admin.myapp:3000',
target: 'http://localhost:3001',
middlewares: [

@@ -32,1 +32,11 @@ require('express-jwt')({

})
const service1 = require('restana')({})
service1
.get('/hi', (req, res) => res.send('Hello World!'))
.start(3000).then(() => console.log('Public service listening on 3000 port!'))
const service2 = require('restana')({})
service2
.get('/users', (req, res) => res.send([]))
.start(3001).then(() => console.log('Admin service listening on 3001 port!'))

27

index.js

@@ -0,1 +1,3 @@

/* eslint-disable no-useless-call */
const fastProxy = require('fast-proxy')

@@ -7,2 +9,3 @@ const restana = require('restana')

const DEFAULT_METHODS = require('restana/libs/methods')
const send = require('@polka/send-type')

@@ -15,5 +18,5 @@ const gateway = (opts) => {

const server = (opts.restana instanceof Function) ? opts.restana() : restana(opts.restana || {
const server = opts.server || ((opts.restana instanceof Function) ? opts.restana() : restana(opts.restana || {
disableResponseEvent: true
})
}))

@@ -31,3 +34,3 @@ // registering global middlewares

server.get('/services.json', (req, res) => {
res.send(services)
send(res, 200, services)
})

@@ -46,2 +49,5 @@

// populating route middlewares
route.middlewares = route.middlewares || []
// populating pathRegex if missing

@@ -69,10 +75,10 @@ route.pathRegex = undefined === route.pathRegex ? opts.pathRegex : String(route.pathRegex)

if (server[method]) {
server[method](
// path
server[method].apply(server, [
// path
route.prefix + route.pathRegex,
// route middlewares
...route.middlewares,
// route handler
handler(route, proxy, proxyHandler),
// route middlewares
route.middlewares
)
handler(route, proxy, proxyHandler)
])
}

@@ -108,3 +114,4 @@ })

} catch (err) {
res.send(err)
res.statusCode = 500
res.end(err.message)
}

@@ -111,0 +118,0 @@ } else {

{
"name": "fast-gateway",
"version": "1.5.1",
"version": "1.5.2",
"description": "A Node.js API Gateway for the masses!",

@@ -29,2 +29,3 @@ "main": "index.js",

"dependencies": {
"@polka/send-type": "^0.5.2",
"fast-proxy": "^1.3.0",

@@ -36,2 +37,3 @@ "http-cache-middleware": "^1.2.3",

"devDependencies": {
"express": "^4.17.1",
"chai": "^4.2.0",

@@ -38,0 +40,0 @@ "cors": "^2.8.5",

# fast-gateway
A super fast Node.js API Gateway for the masses!
A super fast, framework agnostic Node.js API Gateway for the masses ❤️

@@ -38,4 +38,12 @@ ## Medium articles:

{
// Optional server instance. Any HTTP framework that supports the following signature is compatible:
// - server[HTTP_METHOD](pattern, [middleware1, middleware2,], handler)
//
// Known compatible frameworks: Restana, Express.js
// If omitted, restana is used as default HTTP framework
server,
// Optional restana library configuration (https://www.npmjs.com/package/restana#configuration)
// If the given value is a function instead of an object, it will be considered a restana service factory.
// If the given value is a function instead of an object, it will be considered a restana server factory.
//
// If "server" is provided, this settings are ignored.
restana: {},

@@ -42,0 +50,0 @@ // Optional global middlewares in the format: (req, res, next) => next()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc