3. Create npm task to execute, e.g. "proxy": "node ./proxy"
4. Run and configure proxy's connection to the environment by npm run proxy
5. Configure a task to start proxy and gulp serve at the same time, e.g. using concurrently or npm-run-all
6. In SPFx webpart use detection of a local mode with:
import { Environment, EnvironmentType } from '@microsoft/sp-core-library';
if (Environment.type === EnvironmentType.Local) {
// Local mode
}
7. If local mode, target request to proxy's endpoint
Example for sp-pnp-js:
if (Environment.type === EnvironmentType.Local) {
this.web = new Web('https://localhost:4323/sites/site/web');
} else {
setup({ spfxContext: this.context });
this.web = new Web(this.context.pageContext.web.absoluteUrl);
}
1. Install SharePoint REST Proxy in SPFx solution project
2. Create
proxy.js
file in a root or wherever in the project with the following content:3. Create npm task to execute, e.g.
"proxy": "node ./proxy"
4. Run and configure proxy's connection to the environment bynpm run proxy
5. Configure a task to start proxy andgulp serve
at the same time, e.g. usingconcurrently
ornpm-run-all
6. In SPFx webpart use detection of a local mode with:7. If local mode, target request to proxy's endpoint Example for
sp-pnp-js
: