Reputation: 1442
In the following express/gulpfile.js code, I am having an issue with express serving the index.html
fine but the index itself cannot hit the lib/*
directory and just 404s all the requests made at the top of my index.html
.
I am proxying browser-sync with nodemon. However I'm pretty sure it has nothing to do with my browser-sync config because when I just use node config/server.js
the same problem persists.
Express config:
var express = require('express');
var path = require('path');
var filePaths = require('./filePaths');
var app = express();
//filePaths.releaseIndex === './release/index.html'
app.get('/', function (req, res) {
res.sendFile(filePaths.releaseIndex, {root: './'});
});
app.listen(5000);
Gulp task config:
//filePaths.release === './release'
//filePaths.server === './config/server.js'
gulp.task('browser-sync', ['nodemon'], function() {
browserSync.init(null, {
proxy: "http://localhost:5000",
files: [filePaths.release],
browser: "google chrome",
port: 7000
});
});
gulp.task('nodemon', function (cb) {
var started = false;
return nodemon({
script: filePaths.server
}).on('start', function () {
if (!started) {
cb();
started = true;
}
});
});
index.html:
<script src="lib/es6-shim.min.js"></script>
Folder structure:
config
server.js
release
index.html
lib
es6-shim.min.js
Rx.js
...
I've tried many different variations in the res.sendFile()
but just can't get a foothold although I am sure that it is the problem.
Any ideas?
Upvotes: 0
Views: 91
Reputation: 195
Your server does not handle any other paths than /
. To handle them you could add this after your first route:
app.get('*', function (req, res) => {
res.sendFile(req.url, {root: filePaths.release})
});
Upvotes: 1