File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,17 @@ const parseInitConfig = (...args) => {
5656 }
5757}
5858
59+ const validateConfig = config => {
60+ if ( config . domain ) {
61+ if ( ! config . domain . startsWith ( 'https://' ) && ! config . domain . startsWith ( 'http://' ) ) {
62+ throw new Error (
63+ 'When initialize the SDK with a custom domain it should start with http:// or https://, ' +
64+ 'for example: Backendless.initApp(\'https://foobar.com\')'
65+ )
66+ }
67+ }
68+ }
69+
5970const SERVICES = {
6071 'Logging' : ( ) => require ( './logging' ) . default ,
6172 'Counters' : ( ) => require ( './counters' ) . default ,
@@ -113,6 +124,8 @@ class Backendless {
113124 initApp ( ) {
114125 const config = parseInitConfig ( ...arguments )
115126
127+ validateConfig ( config )
128+
116129 const app = config . standalone
117130 ? new Backendless ( this )
118131 : this
Original file line number Diff line number Diff line change @@ -102,6 +102,22 @@ describe('Namespace', function() {
102102 expect ( Backendless . appPath ) . to . be . equal ( `${ CUSTOM_DOMAIN } /my-api-uri` )
103103 expect ( Backendless . apiURI ) . to . be . equal ( '/my-api-uri' )
104104 } )
105+
106+ it ( 'should fails with custom domain which does not start on https or http' , ( ) => {
107+ const errorMsg = (
108+ 'When initialize the SDK with a custom domain it should start with http:// or https://, ' +
109+ 'for example: Backendless.initApp(\'https://foobar.com\')'
110+ )
111+
112+ expect ( ( ) => Backendless . initApp ( 'foobar.com' ) ) . to . throw ( errorMsg )
113+ expect ( ( ) => Backendless . initApp ( 'httpsfoobar.com' ) ) . to . throw ( errorMsg )
114+ expect ( ( ) => Backendless . initApp ( 'https:foobar.com' ) ) . to . throw ( errorMsg )
115+ expect ( ( ) => Backendless . initApp ( 'https:/foobar.com' ) ) . to . throw ( errorMsg )
116+ expect ( ( ) => Backendless . initApp ( 'httpfoobar.com' ) ) . to . throw ( errorMsg )
117+ expect ( ( ) => Backendless . initApp ( 'http:foobar.com' ) ) . to . throw ( errorMsg )
118+ expect ( ( ) => Backendless . initApp ( 'http:/foobar.com' ) ) . to . throw ( errorMsg )
119+ expect ( ( ) => Backendless . initApp ( 'file://foobar.com' ) ) . to . throw ( errorMsg )
120+ } )
105121 } )
106122
107123 describe ( 'Debug Mode' , ( ) => {
You can’t perform that action at this time.
0 commit comments