using the api config entry
Just trying to implement this and can't work out how.
In my gulpfile I created the following entry
build.serve.setConfig({
initialPage: '/',
api: {
entryPath: 'api.js',
}
});
and in my api.js had the following simple piece of code
let path = require('path');
export default function(req, res) {
res.sendFile(path.join(__dirname+'/index.html'));
}
Can't work out what the entryPath needs to be. Have tried just 'api', './api' and those don't work either.
Any ideas or examples I can look at?
What is the error that you're getting? Keep in mind that if you're just serving files from your project directory, you don't need an API file. Serving files is the serve task's default behavior.
See this code - the entryPath property is loaded with a require statement under the rootPath, so if that's where your api.js file is, you should be good.
We usually debug using Visual Studio Code. If you're stuck, try opening your project in VS Code and create an entry for gulp in your launch.json file (if you hit F5, it'll create that file for you, gulp is usually at node_modules/gulp/bin/gulp.js), and step through the serve code to see why it's not able to find your API file.
I'm using react-router with browserHistory and need to return something when refreshing on a route. The docs on react-router suggest setting up the above code.
I'll try what you've suggested to and get back to you shortly. Thanks
@statto1974 , I am closing this issue. If you still have trouble, feel free to reopen it with more details.