Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML5 PushState #787

Closed
syarul opened this issue Aug 26, 2015 · 4 comments
Closed

HTML5 PushState #787

syarul opened this issue Aug 26, 2015 · 4 comments

Comments

@syarul
Copy link

syarul commented Aug 26, 2015

Is there anyway to set up browser-sync server to send my app at every non-static-asset url?

or browsersync to support HTML5 PushState

@shinnn shinnn closed this as completed Aug 28, 2015
@shinnn shinnn reopened this Aug 28, 2015
@syarul
Copy link
Author

syarul commented Aug 28, 2015

ok I try to look into it, btw tinkering with express with the same issue.

@syarul
Copy link
Author

syarul commented Aug 28, 2015

Alright I manage to solve this by looking to pushstate-server by scottcorgan.
To solve this I need to create a middleware with express, I did try to use serve-static middleware but get some errors with request to root path. So this might be good as additional setup in the example folder

/**
 *
 * Install:
 *      npm install browser-sync pushstate
 *
 * Run:
 *      node <yourfile.js>
 *
 * This example will create a middleware to serve files from within a given root directory
 * with mod rewrite and compression, this will enable push state and history location callback
 * 
 */

"use strict";

var bs = require("browser-sync").create();
var express = require('express');
var modRewrite = require('connect-modrewrite');
var compression = require('compression');
var path = require('path');
var app = express();

//the root directory of serve static files
var publicPath = path.resolve(__dirname, 'public');

/**
 * Register with express
 */
app.use(express.static(publicPath));

app.use(modRewrite([
      '!\\.html|\\.js|\\.json|\\.ico|\\.csv|\\.css|\\.png|\\.svg|\\.eot|\\.ttf|\\.woff|\\.appcache|\\.jpg|\\.jpeg|\\.gif /index.html [L]'
    ]));
app.use(compression());

/**
 * Start the Browsersync server and
 * load the express app as middleware
 */
bs.init({
    server: "./app",
    middleware: [app]
});

If you ok with this, I send a pull request

@syarul
Copy link
Author

syarul commented Aug 28, 2015

heh but console keep spewing socket.io pool errors..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants