GithubHelp home page GithubHelp logo

expressgateway / express-gateway-plugin-rewrite Goto Github PK

View Code? Open in Web Editor NEW
11.0 5.0 9.0 1.53 MB

A plugin to rewrite urls for Express Gateway

Home Page: https://www.express-gateway.io/docs/policies/rewrite

License: Apache License 2.0

JavaScript 100.00%
express-gateway express-plugin

express-gateway-plugin-rewrite's Introduction

express-gateway-plugin-rewrite

This plugin for Express Gateway makes it possible to redirect (rewrite internally or redirect using HTTP codes) User to the specific URL based on Express Paths or RegExp Rules.

Installation

Simply type from your shell environment:

eg plugin install express-gateway-plugin-rewrite

Quick start

  1. Make sure the plugin is listed in system.config.yml file. This is done automatically for you if you used the command above.

  2. Add the configuration keys to gateway.config.yml file.

policies:
  -
    rewrite:
      -
        condition:
          name: pathmatch
          match: /tina/:code
        action:
          rewrite: /status/:code
          redirect: 302
      -
        condition:
          name: regexpmatch
          match: ^/js/(.*)$
        action:
          rewrite: /src/js/$1

Configuration Parameters

condition.pathmatch: Express Path corresponding to the url pattern to look for.

condition.regexpmatch: RegExp corresponding to the url pattern to look for.

Note: if you provide both expression, the first one that will match will make the Gateway jump to the policy directly.

action.rewrite: Express Path or RegExp corresponding to the url pattern to rewrite. The format should match the one used in the condition.

action.redirect: If omitted, a rewrite action will be performed. When set to a number, it'll redirect the request with the provided status code.

Want to make your own plugin?

Just check out our plugin development guide. We can't wait to see your custom stuff in the Gateway!

express-gateway-plugin-rewrite's People

Contributors

dependabot[bot] avatar toryalsip avatar xvincentx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

express-gateway-plugin-rewrite's Issues

express-gateway v1.6 appears to break this plugin

After updating to 1.6, express gateway complains that rewrite's schema is missing the "$id" property

Downgrading back to 1.5 fixes the error.

[EG:gateway] rewrite plugin hasn't provided a schema. Validation for this plugin will be skipped. Error: The schema must have the $id property.

Could not modify the headers

image

As I want to change the referer by remove it and add it. But this block of code perform the adding first then removing after. Thus, my changes were removed after added.

It had better to perform the removing first.
Thanks

gateway crashes when using rewrite plugin

Hi,
This issue is related to #3 which was closed.

I'm using express-gateway 1.7.2. After installing express-gateway-plugin-rewrite(1.1.1) using command:
"eg plugin install express-gateway-plugin-rewrite", I configured "gateway.config.yml" as:

policies:
      - rewrite:
        - condition:
            name: regexpmatch
            match: ^/auth/(.*)$
        - action:
            rewrite: /$1

Starting the gateway, it crashed with following error:

warn: [EG:gateway] rewrite plugin hasn't provided a schema. Validation for this plugin will be skipped.
/Users/canho/projects/tmp/gridly-gw/node_modules/express-gateway-plugin-rewrite/node_modules/path-to-regexp/index.js:105
  if (path || index < str.length) {
                         ^

TypeError: Cannot read property 'length' of undefined
    at parse (/Users/canho/projects/tmp/gridly-gw/node_modules/express-gateway-plugin-rewrite/node_modules/path-to-regexp/index.js:105:26)
    at Function.compile (/Users/canho/projects/tmp/gridly-gw/node_modules/express-gateway-plugin-rewrite/node_modules/path-to-regexp/index.js:120:27)
    at policy (/Users/canho/projects/tmp/gridly-gw/node_modules/express-gateway-plugin-rewrite/manifest.js:31:42)
    at policy.policy.args (/Users/canho/projects/tmp/gridly-gw/node_modules/express-gateway/lib/policies/index.js:30:16)
    at pipelinePoliciesConfig.forEach.policyConfig (/Users/canho/projects/tmp/gridly-gw/node_modules/express-gateway/lib/gateway/pipelines.js:134:32)
    at Array.forEach (native)

Is the configuration invalid & the gateway unable to validate it due to missing schema ?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Express gateway crashing due to invalid code in rewrite plugin dependency

After installing the rewrite plugin via the CLI and attempting to start the gateway, I receive an error from the path-to-regexp dependency of the rewrite plugin:

npm start

> [email protected] start /Users/thivu/Development/trip-planner-api
> node server.js

/Users/thivu/Development/trip-planner-api/node_modules/express-gateway-plugin-rewrite/node_modules/path-to-regexp/index.js:99
  if (path || index < str.length) {
                          ^

TypeError: Cannot read property 'length' of undefined
    at parse (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway-plugin-rewrite/node_modules/path-to-regexp/index.js:99:27)
    at Function.compile (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway-plugin-rewrite/node_modules/path-to-regexp/index.js:114:27)
    at policy (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway-plugin-rewrite/manifest.js:13:42)
    at pipelinePoliciesConfig.forEach.policyConfig (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway/lib/gateway/pipelines.js:166:32)
    at Array.forEach (<anonymous>)
    at configurePipeline (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway/lib/gateway/pipelines.js:142:26)
    at Object.module.exports.bootstrap (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway/lib/gateway/pipelines.js:49:18)
    at bootstrap (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway/lib/gateway/index.js:89:26)
    at module.exports (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway/lib/gateway/index.js:19:37)
    at Main.run (/Users/thivu/Development/trip-planner-api/node_modules/express-gateway/lib/index.js:24:27)
    at Object.<anonymous> (/Users/thivu/Development/trip-planner-api/server.js:6:4)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/thivu/.npm/_logs/2017-10-17T23_43_10_162Z-debug.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.