I have a connect server running on localhost, and in my backbone app, if I reload a route, say localhost:8000/fun the server returns Cannot GET /fun obviously because /fun doesn't exist.
Somehow the server needs to know to serve index.html/fun or something. I actually tried that, but I get some other error. Has anyone dealt with this before?
TL;DR Cannot GET /fun
So the basic solution was found here.
You want modRewrite:
npm install connect-modrewrite --save-dev
And in your Gruntfile:
modRewrite = require('connect-modrewrite')
Coffee:
connect:
server:
options:
port: 8765
open: true
base: ['./']
middleware: (connect, options) ->
middlewares = []
middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]']))
options.base.forEach( (base) ->
middlewares.push(connect.static(base))
)
middlewares
Vanilla JS:
connect: {
server: {
options: {
port: 8765,
open: true,
base: ['./'],
middleware: function(connect, options) {
var middlewares;
middlewares = [];
middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]']));
options.base.forEach(function(base) {
return middlewares.push(connect["static"](base));
});
return middlewares;
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With