Nodejs strapi load functions implementation at bootstrap - node.js

I have a backend running on strapi v3 (nodejs), however the answer doesnt need to be strapi specific, nodejs specific is good enough.
We are running for 1 region and are expanding to second region, then for example, a function calculateFee() will have different implementation depending on region app is running on.
We dont want to branch implementation in the function itself , something like if (region == regionA) then { doA ) else { doB } since it's very hard to maintain and expand to yet another region or more.
What I'm thinking of is we have regionA.js. containing its implementation of calculateFee() , regionB has regionB.js containing its own. Then at bootstrap, we pre-load current region's implementation of the function, then the rest of the app behave as usual without changes.
However, i'm not very experienced with nodejs or strapi, and stuck at how to achieve this. Many thanks in advance !

Related

Node.js with Twit - AND Operator issue

I am having an issue getting the twit node.js bot to recognize multiple parameters when attempting to RT when it is both a listed user in the code, as well as containing a specified hashtag.
var stream = bot.stream('statuses/filter', {follow: approved_users, track: '#somehashtag'}
While this seems to work on an either/or basis how can this me modified so that it is an AND condition?
I've been looking through the documentation, and while I am assuming this should be a relatively simple fix I am not familiar enough with node.js to recognize immediately where the issue is.
Any help on this would be greatly appreciated!
Per the Twitter documentation, it is not possible to AND these filter types:
The track, follow, and locations fields should be considered to be
combined with an OR operator. track=foo&follow=1234 returns Tweets
matching "foo" OR created by user 1234.
The only way you'd be able to do something more complicated in real time would be to use the enterprise PowerTrack API, which is a commercial offering.

Define a custom slot type that is no list

I am trying to code a youtube-subscriber-amount skill for Alexa.
If you ask "Alexa, ask subscribercounter for the subscribercount of {Channel}" I want to return {Channel}s subscribercount using youtube data api v3. My Problem is that I'm not sure how to create a slot in Alexa's interaction model, allowing all "strings" (Channelnames).
There was a similar question about two years ago but, it didn't really help me, since the solution was using LITERAL, which isn't available any longer. I've also seen THIS answer, and I tried putting in only "wordOne" but I always get "undefined" if I'm logging the slotvalue in aws. Can anyone help me with creating a slot, allowing every input?

React JS Google Map usage limits

I have just started using React JS and I am currently working on getting the google maps "google-maps-react" package up and running.
From my basic understanding of React JS, any change causes a whole component hierarchy to re-render.
From my understanding of the Google usage information via this link; any re-render constitutes as a usage.
Question
So with that, how do React JS developers handle\deal with this problem? 25,000 free map renders pre-React is fairly substantial but it seems like a fairly simple cap to burst with frameworks like React that cause a re-render for any change in your hierarchy.
Option 1
Is the best way to ensure the map component is not nested in a hierarchy that is updatable by other components? I wrote a sample application and confirmed that only the components in the hierarchy that invoked the change are re-rendered.
If this is the best way, that is fine but I am hoping to hear from more experienced React developers.
Thanks,
I think the 25k limit refers to you requesting the google maps js sdk, not how often you instantiate a google.maps.Map object.
And yes, it would be good practice to not re-render the component encapsulating the map all the time.
Check this simple map component:
https://github.com/Scarysize/react-maps-popup/blob/master/src/map.js
It initializes the map once and propagates the map instance up using a function as a child approach (ofc you could simply pass a callback as a prop).
After some digging I found that the "google-map-react" NPM package is doing something interesting behind the scenes. It is actually sending an update to your markers with the latest map state.
Once I found this, I tied into that behaviour and now my map only renders once and I dynamically handle marker changes based on this behaviour.
I was not able to find this behaviour documented anywhere but happened to stumble upon it via a console.log(JSON.stringify(this.props)) within my marker.

Simple Project in ServiceStack

I'm really struggling with the examples and documentation on ServiceStack. I want to do something really simple but none of the examples given seem to map exactly on what I need. I'm also thrown by the new API section on the website and whether that renders the rest of the (basic) documentation obsolete.
I'm just trying to wrap a number of database entities in a service that exposes CRUD REST and SOAP endpoints (need to retain some SOAP support for use by legacy clients/applications).
Let's call these entities
x: id, description
y: id, name
(they are not related in any way - think I can cope with related ones once I get my head around the very basics)
So I've built a solution:
MyAPI
Global.asx
Web.config
MyAPI.Logic
DB Access code?
MyAPI.SeviceInterface
MyAPiService.cs?
MyAPI.ServiceModel
Operations
x.cs
x.Response
y.cs
y.Response
Types
Don't think I need this but like to overengineer my early projects to make future changes easier
Hopefully this seems sensible
Given the very basic format of entity x, what is the best way to structure x.cs and MyAPIService.cs (I assume entity y would just be treated the same) to achieve basic CRUD operations for both REST and SOAP?
Small point but can I implement two GETs - one that passes in an id (and returns a specific x) and one that doesn't receive an id (and returns a list of all x's)?
I've looked at every link on stackoverflow and servicestack.net already so please no pointers to those - I think I'm just missing the point of the exisitng documentation!!
Many Thanks in Advance
Andy

Orchard Custom Module Return View From Different Module

I recently walked through the Advanced Orchard tutorial on Pluralsight and it really showed me a lot of things I can do to extend Orchard. That said, I was wondering if there is a way for one module to return a view from another module?
The scenario for this is I'm building custom modules for my clients that have features that would be proprietary so I'd want to protect them with an API key, similar to how oForms works. The only difference from mine to theirs is they allow functionality regardless of activation whereas mine wouldn't work at all so I'd like to have a base module that all of my custom modules derive from and each one could do something like:
if (this.IsActivated())
return View("ViewFromThisModule")
else
return View("NotActivatedViewFromBaseModule")
The real purpose behind this would be so I don't have to copy the view(s) utilized in the base module to each custom one for things such as whether the module is activated or not.
Per Betrand's suggestion, instead of going the multiple module route I'll instead do a single module that breaks out features instead. Then I don't need to share anything because the whole thing is self-contained.

Resources