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

Response Callback #309

Closed
1 of 2 tasks
full-stop opened this issue May 21, 2018 · 9 comments · Fixed by #1529
Closed
1 of 2 tasks

Response Callback #309

full-stop opened this issue May 21, 2018 · 9 comments · Fixed by #1529

Comments

@full-stop
Copy link

full-stop commented May 21, 2018

I used it for the first time, and a lot of it was not very clear, but it was very good, thank you for providing this middleware.

  • Operating System: windows7
  • Node Version:8.9.4
  • NPM Version:5.6.0
  • webpack version:3.11.0
  • webpack-dev-middleware Version:2.0.6
  • This is a feature request
  • This is a bug

Code

My suggestion is can you add the support of template engine analysis in the middleware, or provide a callback function for us to use? For example, ejs, jade:

    var ejs = require('ejs');
    
 app.use(webpackDevMiddleWare(complier, {
        stats: {
            assets: true,
            children: false,
            modules: false,
            colors: true
        },
        respCallback: function(res, filename, content) {

            if (/\.html$/.test(filename)) {

                res.send(ejs.render(content.toString(), app.locals));

            } else {
                if (res.send) res.send(content);
                else res.end(content);
            }
        }
    }));

middleware.js#85line

const { respCallback } = context.options;
if (respCallback && typeof respCallback === 'function') {
    respCallback(res, filename, content);
} else {
    if (res.send) res.send(content);
    else res.end(content);

}
@shellscape
Copy link
Contributor

Thanks for the issue. In the future please fill out the entire issue template and don't remove sections.

This seems like a very niche feature and I'm not sure there would be a widespread advantage to users. We'll leave this issue open for some time and if there is a large upvoting of the request we'll consider adding it.

@shellscape shellscape changed the title Hello, I have a suggestion. Feature Request: Response Callback May 27, 2018
@full-stop
Copy link
Author

full-stop commented May 28, 2018

Thanks for the reply, I'll pay attention to the template later, yes, the function of the template engine is very small, but I feel it is very meaningful to provide a response callback, and we can do some custom functions based on this callback.

@alexander-akait
Copy link
Member

/cc @shenguotao2015

@michael-ciniawsky michael-ciniawsky changed the title Feature Request: Response Callback [Feature] Response Callback Aug 23, 2018
@michael-ciniawsky michael-ciniawsky added this to the 3.2.0 milestone Aug 23, 2018
@michael-ciniawsky michael-ciniawsky added this to Feature in Dashboard Aug 25, 2018
@michael-ciniawsky michael-ciniawsky changed the title [Feature] Response Callback Response Callback Aug 25, 2018
@justablob
Copy link

I would like to see this feature aswell, plus having an extra feature can't hurt.

@alexander-akait
Copy link
Member

/cc @justablob Do you want send a PR

@alexander-akait alexander-akait removed this from the 3.5.0 milestone Mar 27, 2019
@alexander-akait alexander-akait added this to the 4.1.0 milestone Feb 1, 2020
@hiroppy
Copy link
Member

hiroppy commented Apr 10, 2020

I can't think of a use case but do you need this feature that provides a callback?

@mitchell-frost
Copy link

I used it for the first time, and a lot of it was not very clear, but it was very good, thank you for providing this middleware.

  • Operating System: windows7

  • Node Version:8.9.4

  • NPM Version:5.6.0

  • webpack version:3.11.0

  • webpack-dev-middleware Version:2.0.6

  • This is a feature request

  • This is a bug

Code

My suggestion is can you add the support of template engine analysis in the middleware, or provide a callback function for us to use? For example, ejs, jade:

    var ejs = require('ejs');
    
 app.use(webpackDevMiddleWare(complier, {
        stats: {
            assets: true,
            children: false,
            modules: false,
            colors: true
        },
        respCallback: function(res, filename, content) {

            if (/\.html$/.test(filename)) {

                res.send(ejs.render(content.toString(), app.locals));

            } else {
                if (res.send) res.send(content);
                else res.end(content);
            }
        }
    }));

middleware.js#85line

const { respCallback } = context.options;
if (respCallback && typeof respCallback === 'function') {
    respCallback(res, filename, content);
} else {
    if (res.send) res.send(content);
    else res.end(content);

}

I would like to work on this feature. Can I have a little more details?

@alexander-akait
Copy link
Member

@mitchell-frost Can you provide real use case?

@bduncanj
Copy link

bduncanj commented Feb 3, 2021

I'm running into a similar issue as outlined in this SO post.

In short, I'm using this indirectly with Angular's ng serve (WebPack dev server) and I need to be able to embed the URL that the dev-server received the request on into my index.html body so that I can calculate a relative href from it. (My user will serve this app from a folder I don't know the path of at build time).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Dashboard
Feature
Development

Successfully merging a pull request may close this issue.

8 participants