Skip to content

Commit

Permalink
change API. now proxy -> path is regExp object
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowwzw committed Mar 26, 2017
1 parent 0c08080 commit 209bb03
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ liteDevServer({
autoInjectClientJS: true,
historyApiFallback: false,
proxy: [
{ path: "api", host: "localhost", port: "8888" },
{ path: "api2", host: "localhost", port: "8888" }
{ path: /\/api/, host: "localhost", port: "8888" },
{ path: /\/api2/, host: "localhost", port: "8888" }
]
});
```
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var path = require("path");
var http = require("http");
var fs = require("fs");
Expand Down Expand Up @@ -89,13 +91,12 @@ var liteDevServer = function liteDevServer(_ref) {
var ext = path.extname(req.url);
console.log("<-- " + req.url);
var matchedProxy = proxy.find(function (item) {
var regExp = new RegExp("^/" + item.path + "(/.*)?$");
return req.url.match(regExp) && item.host && item.port;
return req.url.match(item.path) && item.host && item.port;
});
if (matchedProxy) {
var url = req.url;
var pathRewrite = matchedProxy.pathRewrite;
if (pathRewrite) {
if (pathRewrite && (typeof pathRewrite === "undefined" ? "undefined" : _typeof(pathRewrite)) === 'object') {
url = url.replace(pathRewrite.pattern, pathRewrite.replacement);
}
var options = {
Expand Down
5 changes: 2 additions & 3 deletions indexSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ const liteDevServer = (
const ext = path.extname(req.url);
console.log(`<-- ${req.url}`);
const matchedProxy = proxy.find(item => {
const regExp = new RegExp(`^\/${item.path}(\/.*)?$`);
return req.url.match(regExp) && item.host && item.port;
return req.url.match(item.path) && item.host && item.port;
});
if(matchedProxy){
let url = req.url;
const pathRewrite = matchedProxy.pathRewrite;
if(pathRewrite){
if(pathRewrite && (typeof pathRewrite === 'object')){
url = url.replace(pathRewrite.pattern, pathRewrite.replacement);
}
const options = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lite-dev-server",
"version": "0.4.25",
"version": "1.4.25",
"description": "This is http file server for develpment. This server supports livereload function and proxy function for your api server.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 209bb03

Please sign in to comment.