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

Support custom endpoints and configuration to the react-styleguidist server #273

Merged
merged 7 commits into from
Dec 30, 2016

Conversation

cef62
Copy link
Collaborator

@cef62 cef62 commented Dec 29, 2016

As discussed on gitter this PR enables styleguidist users to add new endpoints to the underlying express server.

A new field it's been added to react-styleguidist config module: configServer.

module.exports = {
  components: './lib/components/**/[A-Z]*.js',
  configServer(app) {
    app.get(
      '/custom', 
      (req, res) => res.send({ response: 'Server invoked' })
    );
  },
};

The registered function receive a pointer to the instanced express server and can add to it new endpoints, configure plugins and middlewares.

This addition is vital for projects requiring access to server-side/filesytem features like the integration with jest snapshot testing (snapguidist) @MicheleBertoli and I are working on.

Let me know if you feel the result is not what we discussed or if you would like some change.

super(props);

this.state = { response: 'No Server Response' };
this.handleInvokeEndpoint = this.handleInvokeEndpoint.bind(this, 'custom');
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you don’t use this second parameter (custom).

return webpackConfig;
},

configServer(app) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it should be configureServer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great! I like configureServer

@@ -44,5 +45,16 @@ module.exports = function(config) {
makeWebpackConfig(env) {
return makeWebpackConfig(config, env || 'production');
},

/**
* Return an info object containing the created server instance and the instanced webapck
Copy link
Member

Choose a reason for hiding this comment

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

webapck

Copy link
Member

Choose a reason for hiding this comment

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

Do we need this in the public API? What’s the use case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed on gitter I'll remove it from the public API

@sapegin
Copy link
Member

sapegin commented Dec 30, 2016

Cool, thanks!

@sapegin sapegin merged commit c92f696 into master Dec 30, 2016
@cef62 cef62 deleted the express-config branch December 30, 2016 11:48
sapegin added a commit that referenced this pull request Jan 2, 2017
## New features

Support custom configuration to the Express server (#273 by @cef62):

app
sapegin added a commit that referenced this pull request Jan 3, 2017
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