Giter Site home page Giter Site logo

peterkingalex1972 / apiredirect Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hpedrorodrigues/apiredirect

1.0 1.0 0.0 53 KB

A beautiful api redirect for all web projects :)

Home Page: https://hpedrorodrigues.github.io/ApiRedirect/

License: MIT License

JavaScript 100.00%

apiredirect's Introduction

APIRedirect

A beautiful api redirect for all web projects.

A improvement from NodeApiRedirect.

Summary

Configuration

Before, see the configuration.sample.json file located at configuration folder.

Files

API Redirect always read configuration.json file located at configuration folder.

Multiple files

You can have several others configuration files, but remember to set default property in configuration.json, like this:

configuration.google.json

{
  "host": "https://google.com",
  "port": 3000,
  "root_folder": "/path/to/project",
  "bind": [
    {
      "uri": "/index",
      "path": "/index.html"
    },
    {
      "uri": "/resources/",
      "path": "/resources/"
    }
  ]
}

configuration.json

{
  "default": "google"
}

In this case, default property is a alias to your API (configuration. + api + .json).

Only one file

You can also have several APIs in only one file, like this:

configuration.google.json

{
  "default": "api_1",
  "api_1": {
    "host": "https://api_1.com",
    "port": 3000,
    "root_folder": "/path/to/project",
    "bind": [
      {
        "uri": "/index",
        "path": "/index.html"
      },
      {
        "uri": "/resources/",
        "path": "/resources/"
      }
    ]
  },
  "api_2": {
    "host": "https://api_2.test.com",
    "port": 4000,
    "root_folder": "/path/to/project",
    "bind": [
      {
        "uri": "/index",
        "path": "/index.html"
      },
      {
        "uri": "/resources/",
        "path": "/resources/"
      }
    ]
  }
}

In this case, default property is a key to your API object (configurationFileContent[api]).

Properties

  • default

required

A alias to your API.

  • host

required

Your API host.

  • port

required

Server listening at this property.

  • root_folder

required

Root folder to your project.

  • bind

required

Object to bind a uri in a path or folder.

He is used in express configuration like this:

app.use(uri, express.static(root_folder + path));

or

app.use(express.static(folder));

Attention: If you using for client side development, needed a url to your index.html file, because all requests at root path are redirected to your API.

For instance:

{
    "uri": "/index",
    "path": "/index.html"
}

Now, just open your API host with /index.

Example: http://localhost:3000/index

  • request

optional

This object is used to set properties for all requests.

  • timeout - Set timeout for all requests, value will be in milliseconds.
  • headers - Any properties in this object will be added in all requests header.

For instance:

"request": {
    "timeout": 60000,
    "headers": {
        "Authorization": "Basic VGhhbmsgeW91IGZvciBkZWNvZGUgdGhpcyBzdHJpbmcuIDop"
    }
}
  • override_responses

optional

This object is used to override responses. Very good to tests.

For instance:

"override_responses": {
    "/login": [
        {
            "field": "targetUrl",
            "value": "http://localhost:3000/index"
        }
    ]
}

In this case, the field targetUrl of response in request /login will be change to http://localhost:3000/index.

value can to accept chain objects like 'myObject.myProperty.test'.

  • log

optional

This object is used to set log properties.

  • colors - Show colors.
  • show_response - Show all responses.
  • show_request_info - Show requests information as status code, time of response, url...
  • show_request_error - Show request errors.

For instance:

"log": {
    "colors": true,
    "show_response": true,
    "show_request_info": true,
    "show_request_error": true
}

How to run

First, type npm install to install dependencies.

In root folder of this project, type:

node main.js

But you can pass some arguments also:

  • -a, --api
  • -h, --host
  • -p, --port

For instance:

node main.js --host http://anotherdomain.test.com --port 3000

Issues

Questions, bug reports, improve documentation, and feature request please search through existing issue or open a one new issue. If you need support send me an email.

Thanks

Augusto Monteiro for multiple configuration files and CLI options.

License

API Redirect is released under the MIT license. See LICENSE for more details.

More

API Redirect is a work in progress, feel free to improve it.

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.