@@ -6,47 +6,24 @@ Missing a server? Feel free to extend this list of examples.
6
6
7
7
<!-- TOC depthfrom:2 insertanchor:false -->
8
8
9
- - [ Browser-Sync] ( #browser-sync )
10
9
- [ Express] ( #express )
11
10
- [ Connect] ( #connect )
11
+ - [ Browser-Sync] ( #browser-sync )
12
12
- [ fastify] ( #fastify )
13
- - [ lite-server] ( #lite-server )
14
13
- [ Polka] ( #polka )
14
+ - [ lite-server] ( #lite-server )
15
15
- [ grunt-contrib-connect] ( #grunt-contrib-connect )
16
- - [ grunt-browser-sync] ( #grunt-browser-sync )
17
16
- [ gulp-connect] ( #gulp-connect )
17
+ - [ grunt-browser-sync] ( #grunt-browser-sync )
18
18
- [ gulp-webserver] ( #gulp-webserver )
19
19
20
20
<!-- /TOC -->
21
21
22
- ## Browser-Sync
23
-
24
- https://github.com/BrowserSync/browser-sync
25
- [ ![ GitHub stars] ( https://img.shields.io/github/stars/BrowserSync/browser-sync.svg?style=social&label=Star )] ( https://github.com/BrowserSync/browser-sync )
26
-
27
- ``` javascript
28
- const browserSync = require (' browser-sync' ).create ();
29
- const { createProxyMiddleware } = require (' http-proxy-middleware' );
30
-
31
- const apiProxy = createProxyMiddleware (' /api' , {
32
- target: ' http://www.example.org' ,
33
- changeOrigin: true , // for vhosted sites
34
- });
35
-
36
- browserSync .init ({
37
- server: {
38
- baseDir: ' ./' ,
39
- port: 3000 ,
40
- middleware: [apiProxy],
41
- },
42
- startPath: ' /api' ,
43
- });
44
- ```
45
-
46
22
## Express
47
23
48
24
https://github.com/expressjs/express
49
25
[ ![ GitHub stars] ( https://img.shields.io/github/stars/expressjs/express.svg?style=social&label=Star )] ( https://github.com/expressjs/express )
26
+ ![ express downloads] ( https://img.shields.io/npm/dm/express )
50
27
51
28
``` javascript
52
29
const express = require (' express' );
@@ -67,6 +44,7 @@ app.listen(3000);
67
44
68
45
https://github.com/senchalabs/connect
69
46
[ ![ GitHub stars] ( https://img.shields.io/github/stars/senchalabs/connect.svg?style=social&label=Star )] ( https://github.com/senchalabs/connect )
47
+ ![ connect downloads] ( https://img.shields.io/npm/dm/connect )
70
48
71
49
``` javascript
72
50
const http = require (' http' );
@@ -84,9 +62,35 @@ app.use(apiProxy);
84
62
http .createServer (app).listen (3000 );
85
63
```
86
64
65
+ ## Browser-Sync
66
+
67
+ https://github.com/BrowserSync/browser-sync
68
+ [ ![ GitHub stars] ( https://img.shields.io/github/stars/BrowserSync/browser-sync.svg?style=social&label=Star )] ( https://github.com/BrowserSync/browser-sync )
69
+ ![ browser-sync downloads] ( https://img.shields.io/npm/dm/browser-sync )
70
+
71
+ ``` javascript
72
+ const browserSync = require (' browser-sync' ).create ();
73
+ const { createProxyMiddleware } = require (' http-proxy-middleware' );
74
+
75
+ const apiProxy = createProxyMiddleware (' /api' , {
76
+ target: ' http://www.example.org' ,
77
+ changeOrigin: true , // for vhosted sites
78
+ });
79
+
80
+ browserSync .init ({
81
+ server: {
82
+ baseDir: ' ./' ,
83
+ port: 3000 ,
84
+ middleware: [apiProxy],
85
+ },
86
+ startPath: ' /api' ,
87
+ });
88
+ ```
89
+
87
90
## fastify
88
91
89
92
https://github.com/fastify/fastify [ ![ GitHub stars] ( https://img.shields.io/github/stars/fastify/fastify.svg?style=social&label=Star )] ( https://github.com/fastify/fastify )
93
+ ![ fastify downloads] ( https://img.shields.io/npm/dm/fastify )
90
94
91
95
``` javascript
92
96
const fastify = require (' fastify' )({ logger: true });
@@ -111,10 +115,33 @@ const { createProxyMiddleware } = require('http-proxy-middleware');
111
115
// curl http://localhost:3000/users
112
116
```
113
117
118
+ ## Polka
119
+
120
+ https://github.com/lukeed/polka
121
+ [ ![ GitHub stars] ( https://img.shields.io/github/stars/lukeed/polka.svg?style=social&label=Star )] ( https://github.com/lukeed/polka )
122
+ ![ polka downloads] ( https://img.shields.io/npm/dm/polka )
123
+
124
+ ``` javascript
125
+ const polka = require (' polka' );
126
+ const { createProxyMiddleware } = require (' http-proxy-middleware' );
127
+
128
+ const app = polka ();
129
+
130
+ app .use (
131
+ createProxyMiddleware ({
132
+ target: ' http://www.example.org' ,
133
+ changeOrigin: true ,
134
+ })
135
+ );
136
+
137
+ app .listen (3000 );
138
+ ```
139
+
114
140
## lite-server
115
141
116
142
https://github.com/johnpapa/lite-server
117
143
[ ![ GitHub stars] ( https://img.shields.io/github/stars/johnpapa/lite-server.svg?style=social&label=Star )] ( https://github.com/johnpapa/lite-server )
144
+ ![ lite-server downloads] ( https://img.shields.io/npm/dm/lite-server )
118
145
119
146
File: ` bs-config.js `
120
147
@@ -138,31 +165,11 @@ module.exports = {
138
165
};
139
166
```
140
167
141
- ## Polka
142
-
143
- https://github.com/lukeed/polka
144
- [ ![ GitHub stars] ( https://img.shields.io/github/stars/lukeed/polka.svg?style=social&label=Star )] ( https://github.com/lukeed/polka )
145
-
146
- ``` javascript
147
- const polka = require (' polka' );
148
- const { createProxyMiddleware } = require (' http-proxy-middleware' );
149
-
150
- const app = polka ();
151
-
152
- app .use (
153
- createProxyMiddleware ({
154
- target: ' http://www.example.org' ,
155
- changeOrigin: true ,
156
- })
157
- );
158
-
159
- app .listen (3000 );
160
- ```
161
-
162
168
## grunt-contrib-connect
163
169
164
170
https://github.com/gruntjs/grunt-contrib-connect
165
171
[ ![ GitHub stars] ( https://img.shields.io/github/stars/gruntjs/grunt-contrib-connect.svg?style=social&label=Star )] ( https://github.com/gruntjs/grunt-contrib-connect )
172
+ ![ grunt-contrib-connect downloads] ( https://img.shields.io/npm/dm/grunt-contrib-connect )
166
173
167
174
As an ` Array ` :
168
175
@@ -211,10 +218,39 @@ grunt.initConfig({
211
218
});
212
219
```
213
220
221
+ ## gulp-connect
222
+
223
+ https://github.com/avevlad/gulp-connect
224
+ [ ![ GitHub stars] ( https://img.shields.io/github/stars/avevlad/gulp-connect.svg?style=social&label=Star )] ( https://github.com/avevlad/gulp-connect )
225
+ ![ gulp-connect downloads] ( https://img.shields.io/npm/dm/gulp-connect )
226
+
227
+ ``` javascript
228
+ const gulp = require (' gulp' );
229
+ const connect = require (' gulp-connect' );
230
+ const { createProxyMiddleware } = require (' http-proxy-middleware' );
231
+
232
+ gulp .task (' connect' , function () {
233
+ connect .server ({
234
+ root: [' ./app' ],
235
+ middleware : function (connect , opt ) {
236
+ const apiProxy = createProxyMiddleware (' /api' , {
237
+ target: ' http://www.example.org' ,
238
+ changeOrigin: true , // for vhosted sites
239
+ });
240
+
241
+ return [apiProxy];
242
+ },
243
+ });
244
+ });
245
+
246
+ gulp .task (' default' , [' connect' ]);
247
+ ```
248
+
214
249
## grunt-browser-sync
215
250
216
251
https://github.com/BrowserSync/grunt-browser-sync
217
252
[ ![ GitHub stars] ( https://img.shields.io/github/stars/BrowserSync/grunt-browser-sync.svg?style=social&label=Star )] ( https://github.com/BrowserSync/grunt-browser-sync )
253
+ ![ grunt-browser-sync downloads] ( https://img.shields.io/npm/dm/grunt-browser-sync )
218
254
219
255
``` javascript
220
256
const { createProxyMiddleware } = require (' http-proxy-middleware' );
@@ -241,37 +277,11 @@ grunt.initConfig({
241
277
});
242
278
```
243
279
244
- ## gulp-connect
245
-
246
- https://github.com/avevlad/gulp-connect
247
- [ ![ GitHub stars] ( https://img.shields.io/github/stars/avevlad/gulp-connect.svg?style=social&label=Star )] ( https://github.com/avevlad/gulp-connect )
248
-
249
- ``` javascript
250
- const gulp = require (' gulp' );
251
- const connect = require (' gulp-connect' );
252
- const { createProxyMiddleware } = require (' http-proxy-middleware' );
253
-
254
- gulp .task (' connect' , function () {
255
- connect .server ({
256
- root: [' ./app' ],
257
- middleware : function (connect , opt ) {
258
- const apiProxy = createProxyMiddleware (' /api' , {
259
- target: ' http://www.example.org' ,
260
- changeOrigin: true , // for vhosted sites
261
- });
262
-
263
- return [apiProxy];
264
- },
265
- });
266
- });
267
-
268
- gulp .task (' default' , [' connect' ]);
269
- ```
270
-
271
280
## gulp-webserver
272
281
273
282
https://github.com/schickling/gulp-webserver
274
283
[ ![ GitHub stars] ( https://img.shields.io/github/stars/schickling/gulp-webserver.svg?style=social&label=Star )] ( https://github.com/schickling/gulp-webserver )
284
+ ![ gulp-webserver downloads] ( https://img.shields.io/npm/dm/gulp-webserver )
275
285
276
286
``` javascript
277
287
const gulp = require (' gulp' );
0 commit comments