Skip to content

Commit 85c4ba7

Browse files
committed
examples: server + proxy
1 parent 924d5e7 commit 85c4ba7

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

examples/server.proxy.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
*
3+
* Install:
4+
* npm install browser-sync express http-proxy-middleware
5+
*
6+
* Run:
7+
* node <yourfile.js>
8+
*
9+
* This example will create a server in the cwd whilst proxying requests
10+
* to /api to a backend
11+
*
12+
*/
13+
14+
"use strict";
15+
16+
var browserSync = require("browser-sync").create();
17+
var express = require('express');
18+
var proxy = require('http-proxy-middleware');
19+
20+
var app = express();
21+
22+
app.use('/api', proxy({target: 'http://www.example.org', changeOrigin: true}));
23+
24+
browserSync.init({
25+
server: ".",
26+
watch: true,
27+
middleware: [app]
28+
});

0 commit comments

Comments
 (0)