File tree 2 files changed +109
-4
lines changed
2 files changed +109
-4
lines changed Original file line number Diff line number Diff line change @@ -251,13 +251,22 @@ class Server {
251
251
setupHistoryApiFallbackFeature ( ) {
252
252
const historyApiFallback = require ( 'connect-history-api-fallback' ) ;
253
253
254
- const fallback =
255
- typeof this . options . historyApiFallback === 'object '
254
+ const options =
255
+ typeof this . options . historyApiFallback !== 'boolean '
256
256
? this . options . historyApiFallback
257
- : null ;
257
+ : { } ;
258
+
259
+ let logger ;
260
+
261
+ if ( typeof options . verbose === 'undefined' ) {
262
+ logger = this . logger . log . bind (
263
+ this . logger ,
264
+ '[connect-history-api-fallback]'
265
+ ) ;
266
+ }
258
267
259
268
// Fall back to /index.html if nothing else matches.
260
- this . app . use ( historyApiFallback ( fallback ) ) ;
269
+ this . app . use ( historyApiFallback ( { logger , ... options } ) ) ;
261
270
}
262
271
263
272
setupStaticFeature ( ) {
Original file line number Diff line number Diff line change @@ -178,6 +178,102 @@ describe('historyApiFallback option', () => {
178
178
} ) ;
179
179
} ) ;
180
180
181
+ describe ( 'as object with the "verbose" option' , ( ) => {
182
+ let consoleSpy ;
183
+
184
+ beforeAll ( ( done ) => {
185
+ consoleSpy = jest . spyOn ( global . console , 'log' ) ;
186
+
187
+ server = testServer . start (
188
+ config ,
189
+ {
190
+ historyApiFallback : {
191
+ index : '/bar.html' ,
192
+ verbose : true ,
193
+ } ,
194
+ port,
195
+ } ,
196
+ done
197
+ ) ;
198
+ req = request ( server . app ) ;
199
+ } ) ;
200
+
201
+ afterAll ( ( ) => {
202
+ consoleSpy . mockRestore ( ) ;
203
+ } ) ;
204
+
205
+ it ( 'request to directory and log' , ( done ) => {
206
+ req
207
+ . get ( '/foo' )
208
+ . accept ( 'html' )
209
+ . expect ( 200 , / F o o b a r / , ( error ) => {
210
+ if ( error ) {
211
+ done ( error ) ;
212
+
213
+ return ;
214
+ }
215
+
216
+ expect ( consoleSpy ) . toHaveBeenCalledWith (
217
+ 'Rewriting' ,
218
+ 'GET' ,
219
+ '/foo' ,
220
+ 'to' ,
221
+ '/bar.html'
222
+ ) ;
223
+
224
+ done ( ) ;
225
+ } ) ;
226
+ } ) ;
227
+ } ) ;
228
+
229
+ describe ( 'as object with the "logger" option' , ( ) => {
230
+ let consoleSpy ;
231
+
232
+ beforeAll ( ( done ) => {
233
+ consoleSpy = jest . spyOn ( global . console , 'log' ) ;
234
+
235
+ server = testServer . start (
236
+ config ,
237
+ {
238
+ historyApiFallback : {
239
+ index : '/bar.html' ,
240
+ logger : consoleSpy ,
241
+ } ,
242
+ port,
243
+ } ,
244
+ done
245
+ ) ;
246
+ req = request ( server . app ) ;
247
+ } ) ;
248
+
249
+ afterAll ( ( ) => {
250
+ consoleSpy . mockRestore ( ) ;
251
+ } ) ;
252
+
253
+ it ( 'request to directory and log' , ( done ) => {
254
+ req
255
+ . get ( '/foo' )
256
+ . accept ( 'html' )
257
+ . expect ( 200 , / F o o b a r / , ( error ) => {
258
+ if ( error ) {
259
+ done ( error ) ;
260
+
261
+ return ;
262
+ }
263
+
264
+ expect ( consoleSpy ) . toHaveBeenCalledWith (
265
+ 'Rewriting' ,
266
+ 'GET' ,
267
+ '/foo' ,
268
+ 'to' ,
269
+ '/bar.html'
270
+ ) ;
271
+
272
+ done ( ) ;
273
+ } ) ;
274
+ } ) ;
275
+ } ) ;
276
+
181
277
describe ( 'in-memory files' , ( ) => {
182
278
beforeAll ( ( done ) => {
183
279
server = testServer . start (
You can’t perform that action at this time.
0 commit comments