Giter Site home page Giter Site logo

Can not access html about elm-live HOT 24 CLOSED

wking-io avatar wking-io commented on May 24, 2024
Can not access html

from elm-live.

Comments (24)

wking-io avatar wking-io commented on May 24, 2024 1

Okay just pushed update! Try elm-live 3.0.6 and let me know!

from elm-live.

wking-io avatar wking-io commented on May 24, 2024 1

@justgook Just released a new version that fixes this problem! Now the behavior is the following:

  • If the url doesn't have an html extension it defaults to the index and lets elm handle routing
  • If the url has an .html extension it will try and serve the file, but if it returns a 404 then it will serve the index and let elm handle routing

from elm-live.

Odalrick avatar Odalrick commented on May 24, 2024

I had the same problem.

I think I traced it to https://github.com/wking-io/elm-serve/blob/edbfbb08fbeb5d7badc3e29dcaf22fe3197cbf38/lib/elm-reload-server.js#L38

Essentially regardless, if the path requested ends with "html", the index gets served.

I worked around it by changing my test file extension to "htm".

edit: That however means that the reload script never gets added to the page.

"Fixed" that by adding <script src="/reload/reload.js"></script> to the source html manually. Which is fine, as long as it is documented.

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

Hey! So are you saying that even without pushstate being turned on you are always having your index.html loaded?

from elm-live.

Odalrick avatar Odalrick commented on May 24, 2024

An autogenerated index-file, yes, as long as the file requested has the "html" extension. At least that's the way it appears.

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

@Odalrick @justgook Do either of you have a repo where the issue happens I can take a look at and test around?

from elm-live.

justgook avatar justgook commented on May 24, 2024

is example not enough ?

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

Oh sure, but if you had an exact representation of your project then I wouldn't have to set anything up and would be able to know without a doubt when I solve your issue! 😊 If you don't that is fine I can set something up. Just want to make sure I get this figured out for you both. 👌

from elm-live.

Odalrick avatar Odalrick commented on May 24, 2024

I created a minimal example in https://github.com/Odalrick/automatic-spork

To recreate the problem as I have it run
yarn run test-test-dev
and go to http://localhost:8000/src/html/test-test.html

http://localhost:8000/src/html/test-test.htm works, but notice that the reload script is manually added.

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

@Odalrick I removed the reload script from test-test.html and ran the command and it worked exactly as expected. Live reload and the page loaded as expected. Am I missing something?

from elm-live.

Odalrick avatar Odalrick commented on May 24, 2024

That's very strange.

What I get is:

screen shot 2018-09-27 at 14 58 29

compared to what I expect:

screen shot 2018-09-27 at 14 58 42

from elm-live.

Odalrick avatar Odalrick commented on May 24, 2024

To be clear, the script runs for on the "html" page, it's just that the static content around the element isn't there, presumably because it sends the index page.

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

This is what I see when I run it:

screenshot 2018-09-27 08 32 12

from elm-live.

Odalrick avatar Odalrick commented on May 24, 2024

This is amazing, I added some console.log to https://github.com/wking-io/elm-serve/blob/edbfbb08fbeb5d7badc3e29dcaf22fe3197cbf38/lib/elm-reload-server.js#L42 .

const finalpath =
  (pushstate || pathname === '/' || pathname === '')
    ? (dir + '/' + startPage)
    : (dir + '/' + pathname);
const test =
  false
    ? (dir + '/' + startPage)
    : (dir + '/' + pathname);
console.log('pushstate', pushstate)
console.log('pathname === \'/\'', pathname === '/')
console.log("pathname === ''", pathname === '')
console.log("(pushstate || pathname === '/' || pathname === '')", (pushstate || pathname === '/' || pathname === ''))
console.log('finalpath', finalpath)
console.log('test     ', test)
console.log("(dir + '/' + startPage)", (dir + '/' + startPage))
console.log("(dir + '/' + pathname)", (dir + '/' + pathname))
console.log('startPage', startPage)
console.log('pathname', pathname)

The output is:

pushstate false
pathname === '/' false
pathname === '' false
(pushstate || pathname === '/' || pathname === '') false
finalpath /Users/ulrik/projects/test-test/index.html
test      /Users/ulrik/projects/test-test/src/html/test-test.html
(dir + '/' + startPage) /Users/ulrik/projects/test-test/index.html
(dir + '/' + pathname) /Users/ulrik/projects/test-test/src/html/test-test.html
startPage index.html
pathname src/html/test-test.html

from elm-live.

Odalrick avatar Odalrick commented on May 24, 2024

I found it!

console.log('pushstate', pushstate)
console.log('typeof pushstate', typeof pushstate)

pushstate false
typeof pushstate string

pushstate is the string "false", which is of course truthy.

Maybe our versions of minimist has changed some detail in defaults? You can of course see the exact version I have in the yarn.lock file.

Seems appropriate that the problem is something that just couldn't happen in Elm.

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

Hahah I know right! :Thanks for finding the problem! I will get a fix figured out and shipped over on elm-serve

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

Closing issue @justgook. Let me know if this issue wasn't resolved for your case with the new release.

from elm-live.

justgook avatar justgook commented on May 24, 2024

clone - https://github.com/justgook/justgook.github.io/tree/develop
Start:
elm-live src/Main.elm --open --pushstate --dir=./gh-pages -- --debug --output=./gh-pages/bundle.js

open: http://localhost:8000/wizardry/level - you will see - that all pages that is level.html, is redirected to index.

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

@justgook Looks like you are using the --pushstate option. That option is what turns on the feature where all paths in the URL are redirected to the index.html on purpose so that Browser.application handles routing clientside. Just remove that option and it will turn that off

from elm-live.

justgook avatar justgook commented on May 24, 2024

dosent it should redirect to index.html only files that not exist in tree?

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

I do not know if I am following?

from elm-live.

justgook avatar justgook commented on May 24, 2024

idea is that im have some webpage, that should redirect to index page, if it try access page that not exist, that is basic pattern of SPA.. all pages that is 404 - should get instead index.html:200

but now im getting index.html, each time, when i try request any html page (IMPO that is wrong)

from elm-live.

wking-io avatar wking-io commented on May 24, 2024

@justgook So what you would expect when using --pushstate is that any url without an extension (html, css, js) should auto serve the index.html, but if you use a url with an extension it should deliver that page?

from elm-live.

justgook avatar justgook commented on May 24, 2024

NO - my expectation is that any file that exist must be served, and if it not exist it must serve index.html (IMPO that is how any SPA works)

from elm-live.

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.