Created
December 19, 2017 01:54
-
-
Save wisetc/eee4ce082696decce7efa572e28d5e97 to your computer and use it in GitHub Desktop.
API service configuration of a vuejs project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import settings from 'settings' | |
export const baseUrls = new ProjectSettings(settings, [ | |
'ibasic-api', 'iqc-api' | |
]).baseUrls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProjectSettings { | |
constructor(settings, serviceNameList) { | |
this.settings = settings | |
this.serviceNameList = serviceNameList | |
this.generateBaseUrls() | |
} | |
getServiceBaseUrl(serviceName) { | |
let server = settings.SERVERS.find(item => | |
item.SERVER_NAME === serviceName | |
) | |
return server ? `http://${server.HOST}:${server.PORT}/${serviceName}` : undefined | |
} | |
generateBaseUrls() { | |
let baseUrls = {} | |
this.serviceNameList.forEach(serviceName => { | |
baseUrls[serviceName] = this.getServiceBaseUrl((serviceName)) | |
}) | |
this.baseUrls = baseUrls | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var settings = { | |
SERVERS: [ | |
{ | |
SERVER_NAME: 'ibasic-api', | |
HOST: '192.168.2.103', | |
PORT: 5555 | |
}, | |
{ | |
SERVER_NAME: 'iqc-api', | |
HOST: '192.168.2.103', | |
PORT: 5555 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment