frandiox / vite-ssr

Use Vite for server side rendering in Node
MIT License
829 stars 92 forks source link

Example of how to actually serve the application using node? #115

Closed mrweiner closed 3 years ago

mrweiner commented 3 years ago

I've ran the build and the dist/server directories are populated, but I don't really understand what I'm supposed to do to actually serve the application. I'm deploying to platform.sh, who has an example for node that includes:

# The configuration of app when it is exposed to the web.
web:
  commands:
    start: "node index.js"

So, in my app, I've replaced this with:

# The configuration of app when it is exposed to the web.
web:
  commands:
    start: "node dist/server/main.js"

That serves up a 502 error, though, so it would seem that things aren't running as expected. Similarly, if I run node dist/server/main.js locally, I don't seem to get any feedback that anything is happening. I'm essentially using https://github.com/frandiox/vitesse-ssr-template/blob/master/src/main.ts with minor additions.

I've never used node before so forgive my ignorance if I'm glancing over something obvious.

frandiox commented 3 years ago

@mrweiner No problem! The thing you built is just a tool for SSR, it is not a Node server in itself. Therefore, you need to create your own Node server and import the thing you built.

There's an example with Express here. You will need to remove everything related to process.argv.

Hope that helps.

mrweiner commented 3 years ago

Ahhhh, okay gotcha, I thought something seemed off. That makes so much more sense! I'll see if i can get things running from that example. Thanks for the insight.

mrweiner commented 3 years ago

@frandiox this was just what I needed to get things running. Thanks again for the help!