lukeed / sirv

An optimized middleware & CLI application for serving static files~!
MIT License
1.06k stars 56 forks source link

Question: re: path to assets (again) #83

Closed tleylan closed 3 years ago

tleylan commented 3 years ago

Hi. I reviewed the closed items and noticed similar questions but... I would like to move the assets folder out from under public as some some companies/projects have shared assets folders. I'm using a Svelte SPA app and whatever sirv install is used with it. My command line in the most simple form is sirv public -s. Is there any command line option to point to another folder to be the root for assets? I don't expressly set up a Node-based server so I don't believe I have that option available to modify.

Thanks.

lukeed commented 3 years ago

Hey, sirv-cli itself only serves one directory. It doesn't have to be "public" of course, but the CLI itself only maps 1 directory to the file server it provides.

If you want to, say, have static/assets and public/assets both map to the /assets URL prefix, you can do that through sirv programmatically. Something like:

const assets1 = sirv('public/assets');
const assets2 = sirv('static/assets');

polka()
  .use('/assets', assets1, assets2)
  // ...

You need something like a Polka to take on that extra proxy/routing step. The only "routing" sirv itself does is a 1:1 lookup between the incoming URL and the file structure. A Polka-type tells sirv: "only pay attention to these or these portions of URLs"

Hope that helps!