-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.js
46 lines (32 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
let tdd = require('./test/_tdd')
module.exports = class ServerlessExpressPlugin {
constructor(serverless, options) {
this.serverless = serverless
this.serverless.service.provider.environment = this.serverless.service.provider.environment || {}
this.environment = this.serverless.service.provider.environment
this.providerName = this.serverless.service.provider.name
// set environment variable SERVERLESS_EXPRESS_PLATFORM to aws, azure, google, etc
this._initialize()
this.commands = {
};
this.hooks = {
};
}
_initialize(){
this.testPlatform()
this.setPlatformEnvironment()
}
// will set environment variable
// will be accessible through process.env
setPlatformEnvironment(){
this.environment['SERVERLESS_EXPRESS_PLATFORM'] = this.providerName
process.env['SERVERLESS_EXPRESS_PLATFORM'] = this.providerName
}
// if platform is not suported
// it will throw an error during intialisation
testPlatform(){
if( tdd.supported_providers.find( n => n === this.providerName ) ){ return }
throw new Error(`Serverless Express Error: provider is not supported yet`)
}
}