Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to serve static before rewrites when using serve option #236

Merged

Conversation

agubler
Copy link
Member

@agubler agubler commented Jan 24, 2019

Type: bug

The following has been addressed in the PR:

  • There is a related issue
  • All code has been formatted with prettier
  • Unit or Functional tests are included in the PR

Description:

When using BTR with StateHistory an index.html is written for each path configured, so when using serve option it shouldn't automatically rewrite index requests to the main index.html. This changes the middleware to try and serve files before re-writing the URL and only re-writes the URL when the index file does not exist.

@codecov
Copy link

codecov bot commented Jan 24, 2019

Codecov Report

Merging #236 into master will increase coverage by 0.23%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #236      +/-   ##
==========================================
+ Coverage    52.6%   52.83%   +0.23%     
==========================================
  Files          10       10              
  Lines         614      617       +3     
  Branches      154      154              
==========================================
+ Hits          323      326       +3     
  Misses        291      291
Impacted Files Coverage Δ
src/main.ts 90.75% <100%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3282b45...f8a07f0. Read the comment docs.

} else {
app.use(express.static(outputDir));
}
serveStatic(app, outputDir, args.mode, args.compression);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the second time serveStatic is called within serve, without any return or conditional in between. Is this deliberate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's is, the first time is before the history middleware and the middleware doesn't call next if it successfully serve a resource. If it doesn't find a resource then it will carry on with the middleware and run the history re-write middleware and then try and serve the re-written resource.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably rename the function to either 'use....' or 'register....'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense. Thanks for the explanation.

} else {
app.use(express.static(outputDir));
}
serveStatic(app, outputDir, args.mode, args.compression);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense. Thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants