Comments (24)
Okay just pushed update! Try elm-live 3.0.6 and let me know!
from elm-live.
@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.
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.
Hey! So are you saying that even without pushstate being turned on you are always having your index.html loaded?
from elm-live.
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.
@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.
is example not enough ?
from elm-live.
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!
from elm-live.
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.
@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.
That's very strange.
What I get is:
compared to what I expect:
from elm-live.
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.
This is what I see when I run it:
from elm-live.
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.
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.
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.
Closing issue @justgook. Let me know if this issue wasn't resolved for your case with the new release.
from elm-live.
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.
@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.
dosent it should redirect to index.html only files that not exist in tree?
from elm-live.
I do not know if I am following?
from elm-live.
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.
@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.
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)
- Constantly opening elm.js after every "build" HOT 2
- Error thrown when trying to run elm-live through Docker HOT 2
- [QUESTION] Plans for tests
- elm-live crash when a file is not found instead responding with a 404 HOT 4
- Support multiple proxies
- Option to ignore self signed certificates in proxied services
- elm-live adds "undefined" text to the document HOT 4
- Reload snippet not inserted when using --proxy-host HOT 1
- file watcher does not work on mounted docker volumes HOT 2
- Request for Release that bumps `http-proxy` to >=1.18.1 HOT 4
- Not refreshing when specifying Elm file in folder. Only watches /src folder for changes. HOT 1
- "-- --output=elm.js" not working as expected in PowerShell HOT 1
- Only certain known filetypes are served
- Proxying does not work HOT 7
- Yarn: Output In Wrong Location when using -- --output='file.js' HOT 2
- Support multiple elm apps (mains)
- Saving the same file over and over again quickly causes problems HOT 2
- anchors seem broken in documentation
- elm-live renders empty page, elm reactor renders correctly HOT 1
- Hot-reload mode completely blank HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elm-live.