Coder Social home page Coder Social logo

Comments (12)

lukejacksonn avatar lukejacksonn commented on May 15, 2024 1

This doesn't really fit into the single page app server ethos. You should really only have one index.html file at the root of your project and load in components from there.

from servor.

lazarljubenovic avatar lazarljubenovic commented on May 15, 2024 1

Ah, right. This is for SPA. I used servor for single-page apps and just continued to use it for regular plain old websites, didn't even think twice. 😄

from servor.

swyxio avatar swyxio commented on May 15, 2024 1

also swimming by to say this was rather unintuitive for me. using servor through svelvet, and it wasn't obvious that this was ONLY for SPAs. i kept refreshing thinking something was wrong. expected there to be a config to serve any existing html files. so i guess count this as a "+1" haha.

usecase - making a svelte site generator, need this for local dev mode

if you'll take a PR and/or give some specs i can try to PR - but also totally cool if you just want to keep it focused on the SPA usecase. my plan would be to add a flag, say --indexes like you suggest, and then modify the isRouteRequest logic and serve the correct file. Ofc if its easier for you to do it then go for it, i dont feel super confident about this stuff :)


edit: hang on... are we just slowly replicating sirv? help me get my head straight here i'm confused how they differ now apart from the zero dep/SPA only thing here

from servor.

odinho avatar odinho commented on May 15, 2024

Do you know any no-dependency projects that has livereload and ssl that isn't "only" for SPA? I've kinda hacked servor for it, will probably just use that, unless I find something better. es-dev-server has lots of deps and slow to install.

from servor.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

Hey man 👋 I do not.. but we could surface this issue again and put the behaviour behind a flag potentially. Like --indexes which would ignore the fallback rules.

What does your hack look like?

from servor.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

So the only reason I was conflicted about this in the first place was that if someone making a SPA visited route /example then currently they would get redirected to /index.html every time, no questions (as it sounds like @sw-yx just found out 😅) but if we enabled this by default then if they visited /example AND /example/index.html existed.. then it would serve that file instead.

Initially I thought this might be confusing but now that everything is behind a flag, users would only experience this new --indexes behaviour intentionally.

In summary, you all make good points and it shouldn't be too hard to implement. Let me have a quick play around with the code.. see whats what!


RE: how they differ now apart from the zero dep/SPA only thing here

The zero dependency thing has been a draw for some people as it makes install very fast (arguably only ~2s faster than sirv to npx but those seconds can add up in a project I guess) and its wysiwyg nature also makes the project very fork/hackable (which I encourage).

image

There is also a slight difference in feature set:

  • Most crucially for me sirv lacks live reload which is done in quite a novel way here (no web sockets to keep it zero dependency)
  • There is also no support for https (or the helpers that come with servor) which some APIs or environments demand to talked to over.
  • Lastly servor finds free ports so that you can run multiple web servers with the same command.

That said.. I'm sure lukeed could implement all of these features in a hot minute if he wanted to. Maybe he made sirv for a slightly different purpose to servor 🤷‍♂ his stuff is always 💯

from servor.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

Alright.. so I have this working but there is one issue I can't get around which you might be able to help me with.

image

Here you can see that with the new flag --static enabled when you visit /nested then the file /nested/index.html is served up. Great 🌈 but the issue is.. I expected it to serve the assets relative to /nested so like /nested/assets/exists.png because I'm not prefixing those resources with a / (thats how I understood relative paths worked).

But it doesn't.. it goes for /assets/exists.png every time. Does anyone know why?

from servor.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

Ahh.. so it seems to work if I add this to the document head:

<base href="/nested/" />

Is this how you would expect it to work? I highly doubt that one would want to have to prefix all the resources in the document with /nested/ or whatever the folder name is called.

I wonder if es module imports respect base like this 🤔

from servor.

swyxio avatar swyxio commented on May 15, 2024

this is surprising to me too. i went ahead and tested it on netlify.

so it seems that on the web, assets/exists.png in /nested resolves correctly to /nested/assets/exists.png. however it seems to behave differently in localhost.

i wouldnt recommend mucking around with <base> tags - thats currently a source of significant pain in Sapper

from servor.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

Hummm.. I wonder what it is then. I googled pretty extensively and didn't find much!

from servor.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

This is now possible in V4 (#51) with the --static flag. See #49 for more info. Thanks for the suggestion all! I'm still wondering if this is in fact the right behaviour though, for two reasons:

  • Firstly I had to inject base urls to get things to get nested relative links to work properly
  • Secondly I wonder about a recursive nested fallback where if given a path /a/b/c and no /a/b/c/index.html exists.. should servor check to see if there is a /a/b/index.html or /a/index.html etc? It makes sense but feels weird..

I welcome any further feedback if anyone has experience/opinions on this! 🙇

from servor.

swyxio avatar swyxio commented on May 15, 2024

wheee!

from servor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.