Code Monkey home page Code Monkey logo

Comments (4)

koltyakov avatar koltyakov commented on June 4, 2024

Hi @MarkusFeldmann,

Are all the sites the Express app talking to share the same credentials?

By using pnp.sp.web the lib tries detect a default baseUrl, it's more a browser's approach. But even in a browser solution, it's better using explicit Web object initiation with strictly providing web URL. Which is definitely a the case for a Node.js application:

For instance:

import { Web } from '@pnp/sp';

const web = new Web('[web_absolute_url]');
web.get().then(w => {
    log.info("[START] Creating metadalist in web %s", siteUrl);
    web.lists.ensure('metadata').then(ler => {
// [...]

This should exclude situations with unpredictable web paths.

Whereas, credentials can't be switched so easily yet this is not important while it's the same clientId/appSecret and the same site collection all the way. Otherwise, with different creds for different methods, sp.setup({ sp: { fetchClientFactory: () => ... } } should be called before each physical request (this scenario is not recommended, IMO, at least we need some design work as this fetch client is global). @patrick-rodgers, please correct me if I'm wrong on this last part.

Hope this helps.

from pnpjs.

MarkusFeldmann avatar MarkusFeldmann commented on June 4, 2024

Hi @koltyakov
Yeah, last night I had a deeper look into the library and found that the approach stores the context globally. So as I am on a schedule I converted the whole thing to to promise based rest. In fact it would be really nice to be able to do it like with C#'s CSOM approach, create a context and simply use it for the request / operation at hand.

anyway: thx
best regards,
Markus

from pnpjs.

koltyakov avatar koltyakov commented on June 4, 2024

I guess we could consider potential context-related enhancements or techniques for multi-contextual (different SiteCollections/credentials) tasks in Node.js/server-side scenarios with PnPjs. Especially in case of growing demand.

Meanwhile, I'm going to close this issue as answered. In a situation with the same credentials, creating new Web('[abs_ur]') should definitely be the cake.

from pnpjs.

github-actions avatar github-actions commented on June 4, 2024

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

from pnpjs.

Related Issues (20)

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.