Skip to content

Commit

Permalink
Add webpack support (as a middleware)
Browse files Browse the repository at this point in the history
  • Loading branch information
galbi101 committed Jul 17, 2017
1 parent 205815c commit ddebf8c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

A static Node.js file web server with options for proxing requests and delaying/mocking responses. Useful for web development.

## What's new

* v0.14.0 - webpack support!

## Installation

```sh
Expand All @@ -31,13 +35,18 @@ The configuration file should be of the following format:
"/lib": "/lib" // i.e. http://<your_host_name>/lib -> <srcDir>/lib
}
},
"proxy": { // (OPTIONAL) A proxy to a remote server for some path patterns
"target": { // can be an object with host and port, or a full url string e.g. "http://myproxy:80"
"host": "hostname",
"port": 80
},
"pathPatterns": [] // e.g. ["^/api/"]
"webpack": {
"confFile": "path/to/your/webpack.config.js"
},
"proxy": [ // (OPTIONAL) proxy servers for some path patterns
{
"target": { // can be an object with host and port, or a full url string e.g. "http://myproxy:80"
"host": "hostname",
"port": 80
},
"pathPatterns": [] // e.g. ["^/api/"] or [{"^/api/": "/"}] (for path rewrite)
}
],
"delay": { // (OPTIONAL) Adding delay to responses for some path patterns
"pathPatterns": [], // e.g. ["^/api/"],
"time": 2000 // the delay amount
Expand Down
5 changes: 4 additions & 1 deletion _swbConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
"/lib": "/lib" // i.e. http://<your_host_name>/lib -> <srcDir>/lib
}
},
"webpack": {
"confFile": "path/to/your/webpack.config.js"
},
"proxy": [ // (OPTIONAL) proxy servers for some path patterns
{
"target": { // can be an object with host and port, or a full url string e.g. "http://myproxy:80"
"host": "hostname",
"port": 80
},
"pathPatterns": [] // e.g. ["^/api/"] or [{"^/api/": "/"}]
"pathPatterns": [] // e.g. ["^/api/"] or [{"^/api/": "/"}] (for path rewrite)
}
],
"delay": { // (OPTIONAL) Adding delay to responses for some path patterns
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "server-with-benefits",
"author": "Gal Ben-Ishay <[email protected]>",
"version": "0.13.0",
"version": "0.14.0",
"engines": {
"node": ">=0.10"
},
Expand All @@ -11,7 +11,9 @@
"http-proxy": "~1.13.2",
"cli-color": "~0.3.2",
"body-parser": "~1.8.3",
"underscore": "~1.7.0"
"underscore": "~1.7.0",
"webpack": "^2.7.0",
"webpack-dev-middleware": "^1.11.0"
},
"bin": {
"swb": "./bin/server"
Expand Down
13 changes: 9 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ conf.servers.forEach(function(serverConf) {
});

}
if (serverConf.static && serverConf.static.srcDir && serverConf.static.paths) {
for (var path in serverConf.paths) {
app.use(path, express.static(serverConf.static.srcDir + serverConf.static.paths[path]));
if (serverConf.webpack) {
app.use(require('webpack-dev-middleware')(require('webpack')(require(serverConf.webpack.confFile))));
}
else if (serverConf.static && serverConf.static.srcDir) {
if (serverConf.static.paths) {
for (var path in serverConf.paths) {
app.use(path, express.static(serverConf.static.srcDir + serverConf.static.paths[path]));
}
}
app.use(express.static(serverConf.static.srcDir));
}
serverConf.static && serverConf.static.srcDir && app.use(express.static(serverConf.static.srcDir));
app.listen(serverConf.port);
console.log(messages);
});

0 comments on commit ddebf8c

Please sign in to comment.