Allows performing API calls to local Express application with forwarding the queries to a remote SharePoint instance.
Original concept of the proxy was created to show how it could be easy to implements real world data communications for SharePoint Framework local serve mode during web parts debug without deployment to SharePoint tenant. Now the tool is used with multiple teams for modern front-end solutions rapid development.
Socket proxying allows to forward API from behind NAT (experimental).
1. Install NPM module in the project:
npm install sp-rest-proxy
2. Create server.js with the following code:
const RestProxy = require('sp-rest-proxy');
const settings = {
configPath: './config/private.json', // Location for SharePoint instance mapping and credentials
port: 8080, // Local server port
staticRoot: './static' // Root folder for static content
};
const restProxy = new RestProxy(settings);
restProxy.serve();
Configuration parameters cheatsheet
3. Add npm task for serve into package.json:
"scripts": {
"serve": "node ./server.js"
}
Check if the path to server.js is correct.
4. Run npm run serve
.
5. Provide SharePoint configuration parameters.
6. Test local API proxy in action.
1. Clone/fork the project:
git clone https://github.com/koltyakov/sp-rest-proxy
2. CMD to the project folder.
3. Install dependencies:
npm install
4. Build:
npm run build
5. Run the server:
npm run serve
or serve in TypeScript directly
npm run ts-serve
Prompts credentials for a SharePoint site.
6. Navigate to http://localhost:8080
(or whatever in settings)
7. Ajax REST calls as if you were in SharePoint site page context:
8. Tests.
npm run test
/* webpack.config.js */
const RestProxy = require('sp-rest-proxy');
const port = process.env.WEBPACK_DEV_SERVER_PORT || 9090;
module.exports = {
// Common Webpack settings
// ...
devServer: {
watchContentBase: true,
writeToDisk: true,
port,
before: (app) => {
// Register SP API Proxy
new RestProxy({ port }, app).serveProxy();
// Other routes
// ...
}
}
};
For Rollup-based workflows, e.g. Vite tools, please check community plugin: rollup-plugin-sp-rest-proxy.
In early days of sp-rest-proxy
, the library was written in ES6 and used module.exports
which was kept after migrating to TypeScript later on for the backward compatibility reasons.
In TypeScript, it's better to import the lib from sp-rest-proxy/dist/RestProxy
to get advantages of types:
import RestProxy, { IProxySettings } from 'sp-rest-proxy/dist/RestProxy';
const settings: IProxySettings = {
configPath: './config/private.json'
};
const restProxy = new RestProxy(settings);
restProxy.serve();
The proxy provides wizard-like approach for building and managing config files for node-sp-auth
(Node.js to SharePoint unattended http authentication).
For more information please check node-sp-auth credential options and wiki pages.Auth settings are stored inside ./config/private.json
.
sp-rest-proxy works with PnPjs (check out brief notice how to configure).
sp-rest-proxy includes helper method for configuring page context - loadPageContext
.
import { loadPageContext } from 'sp-rest-proxy/dist/utils/env';
import { Web } from '@pnp/sp';
// loadPageContext - gets correct URL in localhost and SP environments
loadPageContext().then(async () => {
// In both localhost and published to SharePoint page
// `_spPageContextInfo` will contain correct info for vital props
// PnPjs's Web object should be created in the following way
const web = new Web(_spPageContextInfo.webAbsoluteUrl);
// Then goes ordinary PnPjs code
const batch = web.createBatch();
const list = web.getList(`${_spPageContextInfo.webServerRelativeUrl}/List/ListName`);
const entityName = await list.getListItemEntityTypeFullName();
[1, 2, 3, 4].forEach((el) => {
list.items.inBatch(batch).add({
Title: `${el}`
}, entityName);
});
await batch.execute();
console.log('Done');
}).catch(console.warn);
JSOM can be used in local development mode with sp-rest-proxy with some additional setup.
The local development workbench page should contain JSOM init scripts:
<script type="text/javascript" src="/_layouts/15/1033/initstrings.js"></script>
<script type="text/javascript" src="/_layouts/15/init.js"></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
Check out the example.
Blog post article with setting up SPFx and Proxy
1. SharePoint 2013对REST编程的支持 自从SharePoint2013开始, SharePoint开始了对REST 编程的支持,这样除了.NET , Silverlight, Powershell之外, 又多了一种可以和SharePoint Server进行CSOM编程的方式。那么,问题来了:什么是REST呢?什么是ODATA?为什么这么多产品都开始支持这个了? 2. 什么是R
https://launchpad.support.sap.com/#/notes/3028076 2743182 BC-XI-IBD-MOD UnsupportedOperationException when exeucuting Compoent Check in ESR 2864027 BC-XI-IDE-IFL Sometimes all objects in Integration D
TSPL(Template Signal Processing Library) 是一个 C++ 的信号处理库,主要包括滤波器设计、时频分析和小波变换,同时还包含一些关于向量和矩阵的基本算法,所有的算法基于 C++ 模板类编写而成。
概述 SP-30吸盘可以通过气动元件控制吸附在清洁后的玻璃、金属或者其他光滑的表面上。 参数 材质:硅胶 直径:30mm 高度:17mm 尺寸图纸 搭建案例
更新: 我能够让ADFS将我的用户转发到依赖方应用程序。我使用了ComponentSpace的SAML2.0库和RelayState。即使它成功地转发到WIF应用程序,它也不会将我的用户识别为已通过身份验证。相反,它通过重定向到IDP STS来启动SP启动的SSO场景。我不太确定该怎么办。 原始消息: 我以以下方式配置了单点登录设置: IDP-向我的SP发布SAML2响应的门户网站。 SP-ADF
我是KeyClope的新手,正在尝试将其配置为SalesForce客户端的SAML IDP。IDP启动的SSO流工作正常。我被引导到Salesforce主页正确地进行身份验证。然而,SP启动的SSO给了我一个JSON输出,而不是KeyClope登录页面。 这是SalesForce重定向到的URL(屏蔽IP):http://10.99.xxx.xxx:8080/auth/realms/test?SA
我正在进行SP启动的SSO。 IDP是PingOne 我一直在做IDP发起的SSO。 因此,我们有IDP启动的SSO设置,一切都很正常。我们现在必须让它启动。 我理解它背后的理论,但我不知道如何实施它! 到目前为止,我在想我需要给他们的网址是这样的,也许???: https://sso/saml2/jsp/spSSOInit.jsp?metaAlias=/{idpRealm}/sp 但是当我击中它
昨天下午面的,今天更一下 全程45min 面试官是一眼看着就是大佬级别的人物 项目(15min) 让我自己介绍项目,有哪些功能点,难点 然后遇到他稍微感兴趣的会问一下,没有深挖太多,因为我项目比较烂😂,所以草草就结束了 算法题(30min) 华容道 数组和最大的一个区间 闲言碎语(不想看直接跳过) 没错,15分钟一过就开始手撕算法了。面试官笑着问我,你知道华容道吗?我当时表面平静,但内心已顿感不