File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
examples/on-before-setup-middleware Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ # onBeforeSetupMiddleware
2
+
3
+ Provides the ability to execute custom middleware prior to all other middleware internally within the server.
4
+
5
+ ** webpack.config.js**
6
+
7
+ ``` js
8
+ module .exports = {
9
+ // ...
10
+ devServer: {
11
+ onBeforeSetupMiddleware : (devServer ) => {
12
+ devServer .app .get (" /before/some/path" , (_ , response ) => {
13
+ response .send (" before" );
14
+ });
15
+ },
16
+ },
17
+ };
18
+ ```
19
+
20
+ To run this example use the following command:
21
+
22
+ ``` console
23
+ npx webpack serve --open
24
+ ```
25
+
26
+ ## What Should Happen
27
+
28
+ 1 . The script should open ` http://localhost:8080/ ` in your default browser.
29
+ 2 . You should see the text on the page itself change to read ` Success! ` .
30
+ 3 . Go to ` http://localhost:8080/before/some/path ` , you should see the text on the page itself change to read ` before ` .
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ const target = document . querySelector ( "#target" ) ;
4
+
5
+ target . classList . add ( "pass" ) ;
6
+ target . innerHTML = "Success!" ;
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ // our setup function adds behind-the-scenes bits to the config that all of our
4
+ // examples need
5
+ const { setup } = require ( "../util" ) ;
6
+
7
+ module . exports = setup ( {
8
+ context : __dirname ,
9
+ entry : "./app.js" ,
10
+ devServer : {
11
+ onBeforeSetupMiddleware : ( devServer ) => {
12
+ devServer . app . get ( "/before/some/path" , ( _ , response ) => {
13
+ response . send ( "before" ) ;
14
+ } ) ;
15
+ } ,
16
+ } ,
17
+ } ) ;
You can’t perform that action at this time.
0 commit comments