rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

using the api config entry

Open statto1974 opened this issue 9 years ago • 3 comments

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?

statto1974 avatar Mar 06 '17 12:03 statto1974

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.

iclanton avatar Mar 06 '17 20:03 iclanton

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 avatar Mar 06 '17 20:03 statto1974

@statto1974 , I am closing this issue. If you still have trouble, feel free to reopen it with more details.

qz2017 avatar May 12 '17 22:05 qz2017