Skip to content

refactor: use express recommended api #727

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

Merged
merged 2 commits into from
Oct 19, 2020
Merged

Conversation

nuintun
Copy link
Contributor

@nuintun nuintun commented Oct 16, 2020

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Breaking Changes

Additional Info

@codecov
Copy link

codecov bot commented Oct 16, 2020

Codecov Report

Merging #727 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #727   +/-   ##
=======================================
  Coverage   99.57%   99.57%           
=======================================
  Files          10       10           
  Lines         234      235    +1     
  Branches       71       71           
=======================================
+ Hits          233      234    +1     
  Misses          1        1           
Impacted Files Coverage Δ
src/utils/handleRangeHeaders.js 100.00% <100.00%> (ø)

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 07244b0...09b8c4a. Read the comment docs.

@hiroppy
Copy link
Member

hiroppy commented Oct 16, 2020

thanks, but is this necessary changes?

@nuintun
Copy link
Contributor Author

nuintun commented Oct 16, 2020

@hiroppy In v4.0.0-rc.3 if I hack with koa:

const expressMiddleware = require('webpack-dev-middleware').default;

module.exports = (compiler, options) => {
  const middleware = expressMiddleware(compiler, options);

  const devMiddleware = async (ctx, next) => {
    const locals = ctx.state;
    const set = ctx.set.bind(ctx);
    const get = ctx.get.bind(ctx);
    const send = content => (ctx.body = content);

    await middleware(ctx.request, { set, get, send, locals, setHeader: set }, next);
  };

  Object.keys(middleware).forEach(key => {
    devMiddleware[key] = middleware[key];
  });

  return devMiddleware;
};

set and setHeader ??

#617 might be a better solution!

@alexander-akait
Copy link
Member

@nuintun sorry we never support koa, if you want to support it, please send a PR with tests too

@nuintun
Copy link
Contributor Author

nuintun commented Oct 19, 2020

@evilebottnawi This PR is only for unified API usage, not for compatibility with koa!

res.set('Content-Type', contentType);

res.setHeader('Content-Range', `bytes */${content.length}`);

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

oh, yes, thanks for the PR

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Thanks!

@alexander-akait alexander-akait merged commit 6c8b860 into webpack:master Oct 19, 2020
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.

4 participants