From 209bb03407f7ab4107bcb6e472a3c12c3a6f4c71 Mon Sep 17 00:00:00 2001 From: shadowwzw Date: Sun, 26 Mar 2017 11:49:27 +0400 Subject: [PATCH] change API. now proxy -> path is regExp object --- README.md | 4 ++-- index.js | 7 ++++--- indexSource.js | 5 ++--- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e36967d..174a6e6 100644 --- a/README.md +++ b/README.md @@ -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" } ] }); ``` diff --git a/index.js b/index.js index cda0683..12798ea 100644 --- a/index.js +++ b/index.js @@ -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"); @@ -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 = { diff --git a/indexSource.js b/indexSource.js index bbef546..7fa9043 100644 --- a/indexSource.js +++ b/indexSource.js @@ -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 = { diff --git a/package.json b/package.json index e0c8542..88db46f 100644 --- a/package.json +++ b/package.json @@ -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": {