Http-server: Support HTML5 push-state

Created on 5 Jul 2014  路  33Comments  路  Source: http-party/http-server

How can I use angularjs' html5Mode true.

Need to do some server configuration. What needs to be done? Where?

faq out-of-scope

Most helpful comment

I used superstatic to solve the problem: https://www.npmjs.com/package/superstatic

All 33 comments

+1

Angular JS html5 mode requires a redirect rule which forwards all requests to the index.html.
Would be good to know, if http-server offers any possiblity to create such a redirect rule.

I used superstatic to solve the problem: https://www.npmjs.com/package/superstatic

+1

+1

If you are using ASP.Net MVC I wrote a couple of articles which cover it, I imagine other frameworks are similar in concept at least - http://www.codeproject.com/Articles/806500/Getting-started-with-AngularJS-and-ASP-NET-MVC-P

+1

@bumblebeeman you tutorial is overkill, all you have to do is change RouteConfig.cs:

 routes.MapRoute(
    name: "Default",
    url: "{*anything}",
      defaults: new
      {
        controller = "Home",
        action = "Index",
      }
  );

and then return your index.html in Index method of Home controller.

But how to do it without ASP.NET MVC and where to host?

+1

still no solution to this?

what do you mean, it is resolved, use the snippet above

I'm not using aspnet mvc, so it's not resolved :)

i watched a course by PluralSight "Building AngularJS and Node.js Apps with the MEAN Stack" they do it with Node.js in few first lessons. Also have a look here http://stackoverflow.com/questions/17777967/using-angularjs-html5mode-with-nodejs-and-express

you don't have to call Node REST API then, you can just use Node to help Angular work in html5Mode=true

You're missing the point. I want to use this project, http-server, and be able to handle pushState urls.

+1

+1

(in the meantime if you use Gulp take a look at gulp-webserver)

I used superstatic to solve the problem: https://www.npmjs.com/package/superstatic

Why not use this?

+1

+1

if you tackle this, please try to make it usable without a config file, like superstatic curenlty does it.

A PR is welcome for this if it can be done in an efficient manner.

I think https://github.com/indexzero/http-server/pull/194 would better resolve the issue than https://github.com/indexzero/http-server/issues/205.
At least the option name is clearer, and it doesn't involve redirects.

This looks good. Will try to review this soon. Pretty behind on my maintenance for this project; apologies. Holidays!

any idea when this might be complete? I'm having to use something else to overcome this issue at the moment?

Thanls

Thanks for mentioning superstaic worked well for me.

hey @indexzero :) what's the status on that PR review? Need any help?

+1

+1

+1

@mmahalwy would you mind closing this issue? there's plenty of tooling available for this use case.

This is something the project wants to add. At this point it's clear the user base wants it, so I'm going to lock this issue to ensure it's not lost in the shuffle.

We're planning to add this "self-proxying" approach to the README to address this issue--see https://github.com/indexzero/http-server/issues/338#issuecomment-460648032

That should address this sort of usage without breaking the focus of this project on providing accurate HTTP responses.

The self-proxy hack will be added to the README in #513. Alternatives which explicitly support push-state include spa-http-server, superstatic and pushstate-server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LeaVerou picture LeaVerou  路  5Comments

isomorphisms picture isomorphisms  路  5Comments

dumptyd picture dumptyd  路  4Comments

JonFranchi picture JonFranchi  路  6Comments

jiyinyiyong picture jiyinyiyong  路  6Comments