koltyakov / sp-rest-proxy

🌐 SharePoint API Proxy for local development
MIT License
172 stars 43 forks source link

Setting siteUrl programatically #160

Closed davea38 closed 1 year ago

davea38 commented 1 year ago

Hello!

Is there a mechanism for setting the siteUrl (IProxyContext - which is supplied as part of the configPath settings) programmatically? I've had a look through the types and couldn't see a way to do it?

Could we override siteUrl as part of the settings object that gets passed during the RestProxy constructor maybe?

Many thanks in advance :)

davea38 commented 1 year ago

Or another option might be to declare siteUrl as protected and enable me to subClass and override the value in my custom child class?

NB. the use case for this is me centralising my sharepoint host urls via environment vars / configuration files for local dev as we have several sharepoint environments

koltyakov commented 1 year ago

Hi @davea38,

Maybe this could be helpful https://github.com/koltyakov/node-sp-auth-config#environment-variables if you need binding environment variables?

Generally, you can pass authConfigSettings?: IAuthConfigSettings; to the constructor options.

Also, if it's the same tenant, proxy can be configured with a root pass.

davea38 commented 1 year ago

Thanks for the prompt reply!

I thought about it a bit and actually solved my issue by writing some simple node code that runs prior to the instantiation of the RestProxy class. This checks for the private.json file, then loads it, checks if settings are missing and provides sensible defaults as well as overriding the siteUrl setting from my environment vars.

So now I am controlling my siteUrl centrally and sharing it between sp-rest-proxy, storybook and my react projects via dotenv. Works a treat!

koltyakov commented 1 year ago

Super! Thanks for sharing the feedback.