lukeed / svelte-ssr-worker

A quick demo for rendering Svelte server-side (SSR), but within a Cloudflare Worker!
https://cloudflareworkers.com/#9e1f81f41405f8851b39f4643ce12754:https://tutorial.cloudflareworkers.com/
154 stars 9 forks source link

Navigation #2

Closed rjsandman closed 3 years ago

rjsandman commented 3 years ago

Is this set up possible with navigation? Would you use something like navaid or would you redirect each /page through the cloudflare worker and point it to the corresponding folder on the bucket?

Thanks!

lukeed commented 3 years ago

Yup, those are both viable solutions. I have a new project in the open now that does this for you automatically (still WIP) so I'm not sure if it's worth bringing over the changes to this demo repo.

You can clone freshie/examples/svelte but replace @freshie/ssr.node with @freshie/ssr.worker here.

Replace all workspace: versions with real versions, though

You can freshie build, and then upload the build/client to a GCP bucket (or wherever) and then upload build/server as a CF Worker.

rjsandman commented 3 years ago

Thanks!  This is great!  After npm install and building I'm getting this error:

[freshie] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

---- On Tue, 17 Nov 2020 14:49:55 -0500 Luke Edwards notifications@github.com wrote ----

Yup, those are both viable solutions. I have a new project in the open now that does this for you automatically (still WIP) so I'm not sure if it's worth bringing over the changes to this demo repo. You can clone https://github.com/lukeed/freshie/tree/master/examples/svelte but replace @freshie/ssr.node with @freshie/ssr.worker https://github.com/lukeed/freshie/blob/master/examples/svelte/package.json#L8.

Replace all workspace: versions with real versions, though

You can freshie build, and then upload the build/client to a GCP bucket (or wherever) and then upload build/server as a CF Worker.

— You are receiving this because you authored the thread. Reply to this email directly, https://github.com/lukeed/svelte-ssr-worker/issues/2#issuecomment-729162588, or https://github.com/notifications/unsubscribe-auth/ABCQBRLRDMV3XIDSX44ZZYLSQLHWHANCNFSM4TYR6FDA.

lukeed commented 3 years ago

Oh, sorry 🙈 I linked you to old example.

Since you're likely using styles, you need to install @freshie/plugin.postcss and postcss@7.0.32. Here's the same example, but running PostCSS and TypeScript. Note that you don't actually need to use/setup any PostCSS plugins if you don't want – it's just there to handle CSS output.

rjsandman commented 3 years ago

Okay! That works. Last question... Where do you put the CDN information for the bucket?

lukeed commented 3 years ago

Questions are fine – no docs after all 😆

You create a freshie.config.js in your project root (next to package.json) and add a exports.publicPath key, which defaults to / and gets prepended to all your asset requests.

So if your CDN is going to be at https://static.example.com then your file should have this:

// freshie.config.js
exports.publicPath = function (config, context) {
  return context.isProd ? 'https://static.example.com/' : '/';
}
rjsandman commented 3 years ago

Works great! Wow, this is so simple to use!

Nice work!

lukeed commented 3 years ago

Closing since I think you've migrated over to freshie 😉

rjsandman commented 3 years ago

Looks like the preload is working but not all the urls are updating! Screen Shot 2020-11-20 at 2 17 08 PM

lukeed commented 3 years ago

Those are found in your src/index.html template - which is not currently updated. Synchronizing those paths with publicPath is on the todo list.

You can add the https://.../ path to your HTML template directly for the time being. I'll try to add that fix in today at lunch

lukeed commented 3 years ago

@sandman18 Upgrading to freshie@0.0.8 fixes this. You can leave items like link ... href="/style.css" in your HTML template & it will be synchronized for you.