0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/.changeset/slow-islands-fix.md
Matthew Phillips ba5e2b5e6c
Flagged SSR support (#2548)
* Checkpoint, basics are working

* Add the `--experimental-ssr` flag

* Adds the changeset

* Fixes population of getStaticPaths results

* Pass through the imported module

* Route manifest test

* Fix remaining tests

* Fix remaining tests

* Copy server assets over

* Fix types

* Allowing passing in the request to the Node version of App

* Improve the example app

* Gets CI to pass
2022-02-14 12:48:52 -05:00

1.1 KiB

astro
patch

Experimental SSR Support

⚠️ If you are a user of Astro and see this PR and think that you can start deploying your app to a server and get SSR, slow down a second! This is only the initial flag and very basic support. Styles are not loading correctly at this point, for example. Like we did with the --experimental-static-build flag, this feature will be refined over the next few weeks/months and we'll let you know when its ready for community testing.

Changes

  • This adds a new --experimental-ssr flag to astro build which will result in dist/server/ and dist/client/ directories.
  • SSR can be used through this API:
    import { createServer } from 'http';
    import { loadApp } from 'astro/app/node';
    
    const app = await loadApp(new URL('./dist/server/', import.meta.url));
    
    createServer((req, res) => {
      const route = app.match(req);
      if(route) {
        let html = await app.render(req, route);
      }
    
    }).listen(8080);
    
  • This API will be refined over time.
  • This only works in Node.js at the moment.
  • Many features will likely not work correctly, but rendering HTML at least should.