There's been a few questions around working out if an org is a sandbox or not, but typically these are done via Apex. I need to find out an org's type (only sandbox/prod - dev etc. don't matter) using just the instance URL in Javascript from a Node application.
Current Solution
Worst case scenario I use a REST API call to query the org type and determine the state of play, but the best I've come up with from Javascript right now is to use regex:
var pattern = new RegExp(".*cs[0-9]{1,2}(\.my)?\.salesforce.com");
return pattern.test(instance);
This will return true
for URLs such as "https://cs22.salesforce.com", "https://lacey.cs22.my.salesforce.com" and false
for things like "https://na1.salesforce.com".
Question
Am I missing anything obvious here? Is there some format of Sandbox url I'm not catering for?
It doesn't need to work for every conceivable string thrown at it, it's working on the instanceUrl
returned by Salesforce along with the access tokens etc. during the OAuth flow. What I need is something that's good enough for 99% of the orgs out there right now.