Code Monkey home page Code Monkey logo

sp-rest-proxy's Introduction

sp-rest-proxy - SharePoint REST API Proxy for local Front-end development tool-chains

NPM

npm version Downloads Build Status FOSSA Status Gitter chat

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.

In a nutshell

Supports SPFx and PnP JS

Supported SharePoint versions

  • SharePoint Online
  • SharePoint On-Prem (2019, 2016, 2013)
  • SharePoint On-Prem 2010 (limited support)

Development paradigms

Supports proxying

  • REST API
  • CSOM requests
  • SOAP web services
  • Custom services
  • Static resources

Proxy modes

  • API Proxy server
  • Socket gateway server
  • Socket gateway client
  • Custom Express apps embed mode

Socket proxying allows to forward API from behind NAT (experimental).

How to use as a module

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.

How to develop

Install

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:

REST Client Example

8. Tests.

npm run test

Tests Example

Webpack Dev Server

/* 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
      // ...
    }
  }
};

Rollup Dev Server

For Rollup-based workflows, e.g. Vite tools, please check community plugin: rollup-plugin-sp-rest-proxy.

TypeScript support

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();

Authentication settings

The proxy provides wizard-like approach for building and managing config files for node-sp-auth (Node.js to SharePoint unattended http authentication).

  • SharePoint Online:
    • User credentials (SAML/ADFS)
    • Add-In Only permissions
    • On-Demand authentication (using Electron popup)
  • SharePoint 2019, 2016, 2013:
    • User credentials (NTLM, NTLM v2)
    • ADFS user credentials
    • Form-based authentication (FBA)
    • Form-based authentication (Forefront TMG)
    • Add-In Only permissions
    • On-Demand authentication (using Electron popup)
  • SharePoint 2010:
    • User credentials (NTLM, NTMLv2)
    • Form-based authentication (FBA)
    • Form-based authentication (Forefront TMG)

For more information please check node-sp-auth credential options and wiki pages. Auth settings are stored inside ./config/private.json.

PnPjs

sp-rest-proxy works with PnPjs (check out brief notice how to configure).

PnP JS + sp-rest-proxy

Load page context helper

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 (SharePoint JavaScript Object Model)

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.

SharePoint Framework

Blog post article with setting up SPFx and Proxy

Use cases

  • Client side applications development with local serve, but real data from SharePoint
  • SharePoint Framework in local workbench with real data
  • Client applications integration test automation scenarios

Usage with Docker

License

FOSSA Status

sp-rest-proxy's People

Contributors

airportyh avatar dependabot[bot] avatar fossabot avatar hammadfauz avatar koltyakov avatar mcleanra avatar scatcher avatar snyk-bot avatar svdoever avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sp-rest-proxy's Issues

Usage with Search API

This is a question, than more of an issue, but can this library be used with the SP Search API? I find that the results are not populated in the response

404 error: on call of patch or put from local development only.

While updating request to SharePoint2013 on premises reveived following error
Http failure response for http://localhost:8085/_api/web/lists/getbytitle('ListName')/GetItemById('13'): 404 Not Found. After deploying to sharepoint request is updated successfully.
it occurs only when updating from local. For put and patch methods same issue occuring.
const updateHeader = {
headers: {
"accept": 'application/json;odata=verbose',
'content-Type': 'application/json;odata=verbose',
"X-Http-Method": "MERGE",
'data-type': 'json',
'If-Match': '*',
}
};
Thanks for your work Koltyakov.

Incorrect proxying of WebFaultException

I have custom WCF REST service, hosted in SharePoint. I'm using sp-rest-proxy to test application wich make a request to SharePoint REST API and this custom service.
Everything goes great unless WCR REST service throws an exception.
throw new WebFaultException<string>(ex.ToString(), HttpStatusCode.InternalServerError)
When this code executes, direct GET request returns string response with exception (ex.ToString()).
When I make request through proxy, I got json response with something like that:
{ "type": "Buffer", "data": [ 34, 83, 121, 115, 116, 101, 109, 46, 65, 114, 103, 117, 109, 101 ]}

It's very inconvenient because I can't test exception handling in developer enviroment with sp-rest-proxy, I need to deploy my application to test that behaviour.
If it can be fixed, please do it.
Thank you!

File Upload Fails

We have had issues with uploading files through the sp-rest-proxy. It happens both for uploading to a document folder as well as for uploading an attachment. The error reads:

Cannot read property 'byteLength' of undefined

Here is a screenshot with more details:

screen shot 2017-11-16 at 8 08 53 am

Kerberose Auth

I am trying to use this proxy with an On-Prem 2013 installation that uses Kerberos and tokens are created using IBM Datapower. Getting below error:
{
"readyState": 4,
"responseText": "Invalid message signature: Negotiate",
"status": 500,
"statusText": "Internal Server Error"
}

Is it not supported or am I doing something wrong?

SP2013- On prem- NTLM- Undefined issue

I am getting this from a 2013 on-prem env.
{
"readyState": 4,
"responseText": "401 - undefined",
"status": 401,
"statusText": "Unauthorized"
}
On-deman normally has worked for me other places but here with on-demand, I get this:
{
"readyState": 4,
"responseText": "Cookie array is empty",
"status": 500,
"statusText": "Internal Server Error"
}

Can't get it working with SharePoint online

I have a site on SharePoint online, normally I authenticate with my company e-mail address and my company password. Should this scenario also work with sp-rest-proxy? In this case i'm normally redirected to my company login page and then redirected back to the sharepoint site.

Proxy Issue with GetBuffer of a file with PNP-JS

We have an issue while using PNP-JS and SP-Rest-Proxy.

We are trying to get a Template we have created (Content-Type) (docx).
And upload it in it's content library.

The file uploaded in the lib is always corrupted.

I doesn't know if it the getBuffer() method that get a corrupted stream
or the add() method that corrupt the item while being uploaded with the proxy

Here is the code we use for the file

templateUrl = '/sites/App/Template/Forms/Template/test.docx'
name = 'test.docx'
depositUrl = '/sites/App/Template'

this.web = new Web('http://localhost:8080/sites/App');
this.web.getFileByServerRelativeUrl(this.templateUrl)
    .getBuffer()
    .then((templateData: ArrayBuffer) => { 
        this.web.getFolderByServerRelativeUrl(depositUrl).files.add(name, templateData)); 
});

Here is the code we use for the Proxy Settings

var RestProxy = require('sp-rest-proxy');

const settings = {
    configPath: './sharepoint/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();

The issue discussion started here => pnp/pnpjs#196

Provide settings for OData

Exclude hardcoded 'Accept': 'application/json; odata=verbose' header in requests leaving it as a default option if no accept header is provided.
Provide a way for passing odata modes ('accept: application/json; odata=minimalmetadata', 'accept: application/json; odata=nometadata') via the proxy.

sp-pnp-js batch requests failing with 400: Bad Request

Hi,

I am building an Angular 5 application using sp-rest-proxy for local development. I am getting a 400 bad Request when trying to do a batch request using sp-pnp-js.

SharePoint Version : SharePoint Online
sp-rest-proxy : latest
sp-pnp-js: 3.0.4

const batch = pnp.sp.createBatch();
    array.forEach(element => {
      web.lists.getByTitle('ListName').items(element.Id).inBatch(batch).get()
        .then(data => console.log(data))
        .catch(error => console.log(error));
    });
    batch.execute().then(() => {
      console.log('All is well');
    });

Error:

Error: Error making HttpClient request in queryable: [400] Bad Request
    at new ProcessHttpClientResponseException (exceptions.js:24)
    at eval (core.js:33)
    at ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:4745)
    at ZoneDelegate.invoke (zone.js:387)
    at Zone.run (zone.js:138)
    at eval (zone.js:858)
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4736)
    at ZoneDelegate.invokeTask (zone.js:420)

Please let me know if you need any additional information. Thank you for your great work!

Attachment File Upload Problem

Hi,

I'm trying to add an item with an attachment to a list. Adding an item is OK, but adding an attachment is problematic. The code is below;

pnp.sp.lists.getByTitle("MyList").items.add(item).then(response => {
    response.item.attachmentFiles.add("file.txt", "file content 123");
});

The error:

POST http://localhost:8383/MyList')/items(11)/AttachmentFiles/add(FileName='file.txt') 400 (Bad Request)
Fetch API cannot load http://localhost:8383/MyList')/items(11)/AttachmentFiles/add(FileName='file.txt'). 
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 400. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Uncaught (in promise) TypeError: Failed to fetch

Headers:

General
    Request URL: http://localhost:8383/_api/web/lists/getByTitle('MyList')/items(11)/AttachmentFiles/add(FileName='file.txt')
    Request Method:POST
    Status Code:400 Bad Request
    Remote Address:127.0.0.1:8383
    Referrer Policy:no-referrer-when-downgrade
Response Headers
    Connection:keep-alive
    Content-Length:1048
    Content-Security-Policy:default-src 'self'
    Content-Type:text/html; charset=utf-8
    Date:Thu, 04 May 2017 07:30:25 GMT
    X-Content-Type-Options:nosniff
    X-Powered-By:Express
Request Headers
    accept:application/json
    Accept-Encoding:gzip, deflate, br
    Accept-Language:en-US,en;q=0.8
    Connection:keep-alive
    Content-Length:14
    content-type:application/json;odata=verbose;charset=utf-8
    Host:localhost:8383
    Origin:http://localhost:8080
    Referer:http://localhost:8080/
    User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.36 Safari/537.36
    x-clientservice-clienttag:PnPCoreJS:2.0.4
    x-requestdigest:0xB1B9800178D92F1E17AAE31002BA4F4608B210FCFFDC51F863494EEDBCD5C541781BC78F35C5103F93E4163D10CF81F64AE92C257DB818F38015C4B2CBE21D0F,04 May 2017 07:30:02 -0000
Request Payload
    file content 123

I think, the proxy server responses lack Access-Control-Allow-Origin header for this type of requests.

How can we solve it?

PnP-JS-Core SP.Utilities.Utility methods do not work

Sample code (sendEmail):

const emailProps = {
     To: ["[email protected]"],
     Subject: "This email is about...",
     Body: "Here is the body. <b>It supports html</b>",
};

pnp.sp.utility.sendEmail(emailProps).then(_ => {
     console.log("Email Sent!");
});

Error:
POST http://localhost:8080/_api/contextinfo 404 (Not Found)

private.json clientSecret gets overwritten

I'm using sp-rest-proxy with SharePoint Online, OnlineAddinCredentials authentication strategy. I have clientId and clientSecret in private.json
With version 2.5.3, it worked nicely
After upgrade to 2.5.5. each time I run the proxy (using node myPath/server.js), the clientSecret in private.json get's overwritten by random string (which is 2,5 times longer that the secret).
After downgrading back to 2.5.3 the issue stays until I remove node_modules and yarn.lock file and run yarn again

[ts] Could not find a declaration file for module 'sp-rest-proxy'.

the command: npm i @types/sp-rest-proxy --save
returns the following results:
npm WARN notice Due to a recent security incident, all user tokens have been invalidated. Please see https://status.npmjs.org/incidents/dn7c1fgrr7ng for more details. To generate a new token, visit https://www.npmjs.com/settings/~/tokens or run "npm login".
npm ERR! code E404
npm ERR! 404 Not Found: @types/sp-rest-proxy@latest

any token recreation needed by repository owner?

SharePoint returns other json than proxy

I have the following code:

<!DOCTYPE html>
<html>
<head>
    <title>Show title using REST</title>
    <meta name="viewport" content="width=device-width, maximum-scale=1, user-scalable=no" />

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.0.5/es6-promise.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.1/fetch.min.js"></script>
</head>
<body>
    <h1 id="title">Loading...</h1>
    <script>
        fetch(new Request('/_api/web/title', { credentials: 'include', headers: new Headers({"Accept": "application/json"}) }))
        .then(function(response) {
            return response.json();
        })
        .then(function(json) {
            title = json.value;
            var titleElement = document.getElementById('title');
            titleElement.innerHTML = title;
        })
        .catch(function(ex) {
            console.log('Error:', ex)
        });
    </script>
</body>
</html>

If I execute this through the proxy as index.html I get the following JSON in the body:

{"d":{"Title":"apps"}}

If I upload the page to a SharePoint document library as index.aspx I get the following JSON in the body:

{"odata.metadata":"https://macaw-my.sharepoint.com/personal/serge_macaw_nl/apps/_api/$metadata#Edm.String","value":"apps"}

Is there a way to get the data in the same format so I can develop through the proxy and switch to real SharePoint?

I found the post https://blogs.office.com/2014/08/13/json-light-support-rest-sharepoint-api-released/ for configuring the amount of meta-data, but the settings:

“accept: application/json; odata=verbose”
“accept: application/json; odata=minimalmetadata”
“accept: application/json; odata=nometadata”

don't help in getting output in the same format.

Add a client example?

Hi,
It would be nice to have another example for a nodejs project which uses this npm module, without using Express nor JQuery.
Because now we use :
var restProxy = new RestProxy(settings);
restProxy.serve();
We get your html page using JQuery, which is good for testing.
But I would like to use sp-rest-proxy to create a REST API in my own nodejs sharepoint client project.
Thank you
Bruce

Authorization issue MSIS7068: Access denied

Good day!

I started to receive "Access denied" errors for all my REST requests. Couple of days ago everything was working just fine.

response

headers

terminal

I used version 2.5.0, then updated to 2.5.5 and still have issue.

Normally, I use my corporate laptop (authenticates automatically) to navigate on SP. But, prefer to develop on my Mac. Recently, I had to request Entrust Security token to be able to login from 3rd party computers. But, I had no issues after that.

I paste full url (without localhost) into browser and it successfully returns me data in xml format.

Do you have an idea what could be wrong with authentication?

Sharepoint Online & Angular 5 project

Regards,
Zhandos

Merge request support to update items

To update an item, via rest, need to do a MERGE request or a POST request with X-HTTP-Method set to MERGE. Also need to send If-Match header to ensure the right version is being merged.

Response for such request does not contain Content-Type, which crashes the proxy.

Cannot upload attachment via listdata.svc

Uploading attachment using listdata.svc REST endpoint on server results in error
Invalid slug header for attachment. Slug headers must be of the form "EntitySet,ItemId,Name".

JSOM support documentation

Hi,

Is there any documentation on how to configure sp-rest-proxy to support JSOM operations?
The rest of the operations are working just fine (amazing work!!!): REST, Lists.asmx, ListData.svc but, for some reason, JSOM requests are not proceeding.

Thanks!

sp-pnp-js getAll method fails with sp-rest-proxy 2.5.9

Hi Koltyakov,

Thanks for issuing a fix for the comment I posted yesterday on sp-pnp-js thread here

I updated my proxy server and retried the getAll method. It worked fine for smaller lists but failed for larger lists (above 5000 items). Could you please look into this. Thank you.

Failed to load {{direct url to site here}}: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:1234' is therefore not allowed access. The response had HTTP status code 401. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Angular 4 and SharePoint On-Premise

This is more of a question than an issue

I set up the proxy according to the instructions and placed my credentials in the __private.conf file.
The __private.conf looks like this:

{
  "siteUrl": "https://my_company_SP_site",
  "username": "[username]",
  "password": "[password]",
  "domain": "[our domain]",
  "workstation": "" // don't have this
}

I have a service in Angular that is calling the SP REST API endpoint of
https://my_company's_site/_api/web/lists/GetByTitle(\'categories\')/items?$filter=level%20eq%201&$select=Title

It looks similar to this:

private _landingPageUrl = 'https://my_company's_site/_api/web/lists/GetByTitle(\'categories\')/items?$filter=level%20eq%201&$select=Title';
getMajorCategories(): Observable<any> {
    const headers = new Headers({
      'Accept': 'application/json;odata=verbose',
    });
    const options = new RequestOptions({headers: headers})
    return this._http.get(this._landingPageUrl)
    .do(data => console.log('Categories are: ' + JSON.stringify(data)))
    .catch(this.handleError);
  }

When I attempt to call that service, I am receiving a 403 error that localhost is not allowed access. What should I be I forwarding to my proxy.conf.json file? I followed the set up found in this blog post by John Liu

POST expected data format

Hi,
I managed to make GET calls, but I don't know what is expected for a POST:
I tryed to put in your sample: { '__metadata': { 'type': 'SP.DemandesListItem' }, 'Title': 'ok' } but it gives me an error.
I only want to create an item in a Sharepoint 2013 list

Anyway, a big thank you for sharing this!

Error 500

Hi,

I have problem when trying to get request from Sharepoint.
I did git clone project, built it, serve it and added credentials. After that I get this :
error

Error point to script.js:58.

Thanks in advance and thanks for creating this plugin.

Electron form no longer working for On-Demand auth

Something changed in last 4 month and now when I select on-demand auth option, the electron form is unable to perform authentication. I have been unable to debug the form and get more info on the issue.
I am using it for SharePoint online where PingID is being used for id federation. It was working perfectly fine till September last year. Not very sure when I used last though.

Unauthorized errror.

HI guys

first at all, thanks very much for doing this project. it is very helpful for sharepoint developing. I did all steps to setup the sp-res-proxy and I get the lessage below. I am not sure what is the problems. I check my credentials and they are ok.

{
"readyState": 4,
"responseText": "401 - undefined",
"status": 401,
"statusText": "Unauthorized"
}

I have the followin

const RestProxy = require('sp-rest-proxy');
const path = require('path');
const settings = {
    // Location for SharePoint instance mapping and credentials
    configPath: path.join(__dirname, '/config/private.conf.json'),
    // Local server port
    port: 8081,
    // Root folder for static content
    staticRoot: path.join(__dirname, '/static')
};

const restProxy = new RestProxy(settings);
restProxy.serve();

private.conf.json

{
  "siteUrl": "https://site.ttttt.yyy.uuu",
  "strategy": "OnpremiseUserCredentials",
  "username": "my username",
  "domain": "domain of the username",
  "password": "c73fae4a9117c442c6a63b9bbdb7f3755aa8e3f22326c4160a257fb2bbec31ce253481008028a5141712266a25fb354c3ZMmTNBCBjYiyARRvjfm2JDaDiMidqvRHND1FlUTwSU="
}

package.json

 "scripts": {
...
 "server2": "node ./server.js",
...
}

The dev Machine is the same domain of the development Sharepoint 2013 server. However Dev Machine and Development Sharepoint server are two separated machines.

I really need to put this to work. any help is really appreciated.

Best,
Hmendezm

Bad Request - Invalid Verb

We are experiencing an issue sporadicly and getting Bad Request - Invalid Verb from the proxy.

We were testing with this method to make it pretty simple.

import { sp, List } from '@pnp/sp';

const flow = (list: List) => {
  list.items.add({ Title: new Date().toISOString() })
    .then(({ data }) => {
      setTimeout(() => {
        list.items.getById(data.Id).delete()
          .then(() => flow(list))
          .catch(console.log);
      }, 1000 * 30); // creating and deleting an item per 30 sec until fail 
    });
};

flow(sp.web.lists.getByTitle('My List'));

It took 9h for it to fail.

Here is the request

pnp-call-fail

Here is the response

"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\">\r\n<HTML><HEAD><TITLE>Bad Request</TITLE>\r\n<META HTTP-EQUIV=\"Content-Type\" Content=\"text/html; charset=us-ascii\"></HEAD>\r\n<BODY><h2>Bad Request - Invalid Verb</h2>\r\n<hr><p>HTTP Error 400. The request verb is invalid.</p>\r\n</BODY></HTML>\r\n"

We are using UserCredentials strategy and SharePoint Online for dev.
I will test it again tonight to see if it take around the same time to fail and post it here.

If any more test or informations is required, just ask me, i will do my best to test!

POST Requests Throwing 403 Error

The proxy works great for GET reqeusts. However, when I try to do a POST request to insert a SharePoint list item I receive the following error:

Status Code: 403 Forbidden
"The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again."

I have researched this error and followed suggestions around setting the X-RequestDigest property in the header. Setting X-RequestDigest to a new digest does not solve the issue.

Has anyone been able to get sp-rest-proxy to work for POST requests?

jetNexus NTLM

Hi @koltyakov

Thank you for this amazing plugin. It saved me lots of hours working, instead of constantly deploying and watching what does not work now. Anyway, company had previously been using TMG, and now we switched to jetNexus that is using NTLM, so when I type my credentials and test API I get:

error_ntlm

Tried with authCheck like you explained last time, but I get same error.

Cant seem to download files from sharepoint?

I've been trying to get this working,
For example i'd use the following REST URL

/sites/<COMPANY>/_api/web/GetFileByServerRelativeUrl('/sites/<COMPANY>/Shared Documents/test doc.docx')/$value

and the sp-request will correctly pull down the data.
However the conversion to the expressjs response seems flawed.

I'd added in code to copy all the headers from sp-request to the expressjs response
this has aided a bit - The proxy is now sending by the correct content type.

But i believe the body of the response is not correct. I've tried
res.end(response.body, 'binary');
without much luck. (this replaced the res.json(response.body);

Steve

Register on NPM

First off...VERY cool tool! I have hacked together pieces of this functionality for project specific development several times over the years but this makes it a heck of a lot easier.

Now for the question...would you mind registering this on NPM so I could pull it in as a dev-dependency. I have a few angular-cli projects in development and it would be ideal to spin up the api-proxy at the same time I serve my local client-side assets.

Thanks,
--Scott

Your server as webpack-dev-middleware

As if you don't have enough self-inflicted tasks :-) how about making or helping me make middle-ware
to allow me using WbPack for development and deployment with all the goodies you guys are making.
(sp-save, sp-pnp-node etc..) I saw this:https://webpack.js.org/guides/development/#using-webpack-dev-middleware and thought I can combine the good of both worlds for all of us none o365 client side developers.

Thanks for a great sp-rest-proxy even if you do not make the middle-ware 👍

Unable to develop in the latest version

Hi,

I would like to start with thanking you for this amazing work which has eased in my development.

Coming to the issue, I was previously using version 1.2 (guessing as I deleted older version) and upgraded to the latest version following the steps in the documentation. However, I get an error stating "Cannot find module 'dist\server'.

Error screenshot is attached. Please help.

sp-rest-proxy error

I get /_api/contextinfo 401 (Unauthorized) document upload

When i try upload a document to libary i get 401

Here my code : OPTIONS http://XXXXXX/_api/contextinfo 401 (Unauthorized)

I use sp-pnp-js and your sp-rest-proxy for locally development.

const siteUrl = "http://XXXXXXX/XXXXXXX/";
 this.web = new Web(siteUrl);
 if (file.size <= 10485760) {
   // small upload
   this.web
     .getFolderByServerRelativeUrl("/Shared%20Documents/")
     .files.add(file.name, file, true)
     .then(_ => Logger.write("done"));
 } else {
   // large upload
   this.web
     .getFolderByServerRelativeUrl("/Shared%20Documents/")
     .files.addChunked(
       file.name,
       file,
       data => {
         Logger.log({
           data: data,
           level: LogLevel.Verbose,
           message: "progress"
         });
       },
       true
     )
     .then(_ => Logger.write("done!"));
 }
} 


"dependencies": {
    "@angular/animations": "^5.2.3",
    "@angular/common": "^5.2.3",
    "@angular/compiler": "^5.2.3",
    "@angular/core": "^5.2.3",
    "@angular/forms": "^5.2.3",
    "@angular/http": "^5.2.3",
    "@angular/platform-browser": "^5.2.3",
    "@angular/platform-browser-dynamic": "^5.2.3",
    "@angular/router": "^5.2.3",
    "@angularclass/hmr": "^2.1.3",
    "@ultimate/ngxerrors": "^1.4.0",
    "bevlis-spa-kaf-list": "0.0.31",
    "bootstrap": "^4.0.0",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.3",
    "cssnano": "^3.10.0",
    "font-awesome": "^4.7.0",
    "intl": "^1.2.5",
    "jquery": "^3.3.1",
    "ngx-bootstrap": "^2.0.2",
    "ngx-loading": "^1.0.14",
    "ngx-modal-dialog": "^1.1.1",
    "postcss": "^6.0.17",
    "rxjs": "^5.5.6",
    "sp-pnp-js": "^3.0.5",
    "weakmap": "0.0.6",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.20"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.8",
    "@angular/compiler-cli": "^5.2.3",
    "@angular/language-service": "^5.2.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~9.4.1",
    "codelyzer": "~4.1.0",
    "jasmine-core": "~3.0.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.1",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "sp-rest-proxy": "^2.5.4",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.7.1"
  }

thanks. SP2010

I've had successful results connecting this to SP2010 on-premises.

_api needs to change to _vti_bin/listdata.svc so there were some hacks. But it works 👍

need to think a bit more about how to support this properly, do you want to add a flag to config to specify which SharePoint the user is running?

Problem Uploading File to Document Library

Hi,

I cannot add a file into a document library. The errors are similar to what we had in adding file attachments: HTTP 403 (Bad request), HTTP 413 (Payload too large)

Sample code (using sp-pnp-js),

web.getFolderByServerRelativeUrl("/MyDocumentLibrary/").files.add(fileName, fileData, true);

Full SPAddIn example

Hey,

I'm in a project where we host an angular 5 application in SharePoint 2013 using an SharePoint hosted Add-In. I have tried to use sp-rest-proxy with the add-in, but no luck. Can you please provide a step by step guide on how to use sp-rest-proxy with hosted Add-In?

Thanks!

Proxy SOAP Requests?

Any chance of supporting SOAP requests?

It would be nice to be able to rely purely on REST but unfortunately I still find myself posting to the SOAP web services pretty frequently. I'm looking to add that functionality but would appreciate any input you had before I invest too much time.

Thanks again for the work you've done on this project.

--Scott

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.