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

Custom server support #70

Closed
robinvdvleuten opened this issue May 29, 2017 · 7 comments
Closed

Custom server support #70

robinvdvleuten opened this issue May 29, 2017 · 7 comments

Comments

@robinvdvleuten
Copy link

Instead of having a static production-like server when building for production. It would definitely be awesome to have some kind of "custom server" type of output like next.js has.

@thangngoc89
Copy link
Collaborator

@robinvdvleuten I think preact-cli and next.js are 2 different beasts. You can serve the static build with any server. So no need for support from preact-cli. Just build your own :D

@robinvdvleuten
Copy link
Author

@thangngoc89 I am aware of that, but the preact-cli also has supports for prerendering. It would be nice if there is some sort of exposed API for this so that you still can rely on the webpack / babel configuration of this project :)

@thangngoc89
Copy link
Collaborator

thangngoc89 commented May 29, 2017

@robinvdvleuten I think the prerendering is done in build step. Check out index.html, you'll see the rendered code of your index route. No need for a server here

@developit
Copy link
Member

developit commented May 29, 2017

If we end up with a UMD or CommonJS bundle output from something like #71, you could use preact-cli as an opaque compiler within a Node server. I'm not sure it'd fit perfectly into preact-cli itself, but certainly I could see supporting something like this:

import { h } from 'preact';
import express from 'express';
import { build } from 'preact-cli';
import renderToString from 'preact-render-to-string';

const app = build('./client', { format: 'umd' }).then( output => require(output.main) );

const app = express();
app.get( (req, res) => {
  app.then( App => {
    let body = renderToString(<App url={req.path} />);
    res.send(`<!doctype html><html lang="en">${body}`);
  });
});
app.listen(process.env.PORT);

Or, maybe we expose an full API where you could trigger and handle a client build, or invoke a high level API for SSR like prerender({ url }).

@robinvdvleuten
Copy link
Author

@developit that's exactly the kind of interface I meant! I do not expect that preact-cli becomes some kind of prext.js, but it would be great if it provides some kind of interface / functionality to build this kind of tooling upon. The only thing the preact-cli should do extra I guess is to expose the build process. Is there any way I can help with this?

@developit
Copy link
Member

Any experimentation you have time to do would be appreciated. The API we can solidify later, but I'd love to get some experiments done around returning a reusable "preact compiler" instance.

@robinvdvleuten
Copy link
Author

@developit I've created a PR for exposing a compiler instance, let's continue the discussion there.

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

No branches or pull requests

3 participants