Skip to content

Commit 6020e21

Browse files
evilebottnawihiroppy
authored andcommitted
refactor: setupFeatures method (#1891)
1 parent df6a020 commit 6020e21

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

lib/Server.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -521,51 +521,49 @@ class Server {
521521
},
522522
};
523523

524-
const defaultFeatures = ['setup', 'before', 'headers', 'middleware'];
524+
const runnableFeatures = [];
525525

526-
if (this.options.proxy) {
527-
defaultFeatures.push('proxy', 'middleware');
526+
// compress is placed last and uses unshift so that it will be the first middleware used
527+
if (this.options.compress) {
528+
runnableFeatures.push('compress');
528529
}
529530

530-
const contentBase = this.options.contentBase;
531+
runnableFeatures.push('setup', 'before', 'headers', 'middleware');
531532

532-
if (contentBase !== false) {
533-
defaultFeatures.push('contentBaseFiles');
533+
if (this.options.proxy) {
534+
runnableFeatures.push('proxy', 'middleware');
534535
}
535536

536-
if (this.options.watchContentBase) {
537-
defaultFeatures.push('watchContentBase');
537+
if (this.options.contentBase !== false) {
538+
runnableFeatures.push('contentBaseFiles');
538539
}
539540

540541
if (this.options.historyApiFallback) {
541-
defaultFeatures.push('historyApiFallback', 'middleware');
542+
runnableFeatures.push('historyApiFallback', 'middleware');
542543

543-
if (contentBase !== false) {
544-
defaultFeatures.push('contentBaseFiles');
544+
if (this.options.contentBase !== false) {
545+
runnableFeatures.push('contentBaseFiles');
545546
}
546547
}
547548

548-
defaultFeatures.push('magicHtml');
549-
550549
// checking if it's set to true or not set (Default : undefined => true)
551550
this.serveIndex = this.serveIndex || this.serveIndex === undefined;
552551

553-
const shouldHandleServeIndex = contentBase && this.serveIndex;
554-
555-
if (shouldHandleServeIndex) {
556-
defaultFeatures.push('contentBaseIndex');
552+
if (this.options.contentBase && this.serveIndex) {
553+
runnableFeatures.push('contentBaseIndex');
557554
}
558555

559-
// compress is placed last and uses unshift so that it will be the first middleware used
560-
if (this.options.compress) {
561-
defaultFeatures.unshift('compress');
556+
if (this.options.watchContentBase) {
557+
runnableFeatures.push('watchContentBase');
562558
}
563559

560+
runnableFeatures.push('magicHtml');
561+
564562
if (this.options.after) {
565-
defaultFeatures.push('after');
563+
runnableFeatures.push('after');
566564
}
567565

568-
(this.options.features || defaultFeatures).forEach((feature) => {
566+
(this.options.features || runnableFeatures).forEach((feature) => {
569567
features[feature]();
570568
});
571569
}

0 commit comments

Comments
 (0)