Giter Club home page Giter Club logo

enginx's Introduction

enginx Document

Build Status CocoaPods npm version

Cocoapods:
CocoaPods

npm:
npm

maven:
Download

version: 2.0
config file format: enginx DSL
platform: Android, iOS, Node.js

if you want 1.0 version document, please checkout branch "1.0".

installation

iOS via Cocoapods

pod 'enginx', '~> 2.0'

Android

compile 'cc.stephenw.enginxandroid:enginxandroid:2.0.1'

Node.js

npm install -s [email protected]

Getting Start

write a config file

for example, you want to rewrite https://google.com/user/9527 to google://user?id=9527, here is the config file(string):

server {
  domain: "google.com";
  scheme: "https";
  port: "443";
  location "/user" {
    match $path "^/user/(.*)$";
    # $1 is the variable of "9527"
    return "google://user?id=$1";
  }
}

load the config & do rewrite

  • for iOS
char* config = ...;
enginx_load_config_string(config);

enginx_compile_error* error = enginx_get_current_error();
if (error != NULL) {
//handle error
}

//rewrite
char* url = ...;
char* rewrited_url_string = enginx_rewrite_url(url);

//manage memory
enginx_compile_error_release(&error);
free(rewrited_url_string);
  • for Android
String config = ...; //load config from network, file, etc..
String errorMessage = EnginxAndroid.loadConfig(config);
if (!errorMessage.isEmpty()) {
	//handle error
}
//then use it
String url = EnginxAndroid.rewriteURL(...);
  • for Node.js (server side)
const enginx = require('enginx-nodejs')

//you can catch config error here
enginx.loadConfig('...')

//then use it
enginx.rewriteURLString('...')

enginx concepts

server

server stands for a host that can response the url

fields:

  • domain: required, url domain name
  • scheme: required, url request protocol
  • port: required, 80 for http, 443 for https

location

location is a scope contains instructions for matched path.
matching rules: regex string.

instruction

  • encode/decode
    encode/decode [variable]
    do url encode/decode with global or interal variables.

  • match
    match [variable] [regex string]
    use regex string to extract variables from variables, $0 is the full match, match groups are stored with name $n, n stands for the n-th one.

  • parse
    parse [variable]
    parse variable in query param format, such as the $fragment is string foo=bar, parse $fragment will store $#foo as key, bar as the value in temp variable.

  • var
    var [variable name] [string template]
    var defines variable from string template, then you can access this variable with $variable_name.

variable

enginx has some pre-defined variables:

  • $scheme
  • $host
  • $request_uri
  • $path
  • $fragment
  • $query_string
  • query parameters: use as $arg_key (substitue โ€˜keyโ€™ yourself)

alse you can define variable with specific name, then use it as $variable_name

string template

string template is very important in enginx, which generates variable content and represents final result. Basically, you can use variables in string template, for example:

//sample url
http://sample.com?userid=9527#token=qwerty

//instructions for this url 
parse $fragment;
var timestamp 2017-4-1;

//string template
https://google.com/user/$arg_userid?token=$#token&timpstamp=$timestamp

this string template uses variable from query arguments, parsed variables, and defined variables.

enginx's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

enginx's Issues

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.