Skip to content

Commit a90e2a7

Browse files
authored
Merge pull request #13 from amsross/patch-1
Include dynamic and additional URL formats
2 parents 7e35232 + 8d2418e commit a90e2a7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

index.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ const _ = require('lodash');
77
const mime = require('mime');
88
const fs = require('fs');
99

10+
// per http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints
11+
const regionToUrlRootMap = region => ({
12+
'us-east-2': 's3-website.us-east-2.amazonaws.com',
13+
'us-east-1': 's3-website-us-east-1.amazonaws.com',
14+
'us-west-1': 's3-website-us-west-1.amazonaws.com',
15+
'us-west-2': 's3-website-us-west-2.amazonaws.com',
16+
'ca-central-1': 's3-website.ca-central-1.amazonaws.com',
17+
'ap-south-1': 's3-website.ap-south-1.amazonaws.com',
18+
'ap-northeast-2': 's3-website.ap-northeast-2.amazonaws.com',
19+
'ap-southeast-1': 's3-website-ap-southeast-1.amazonaws.com',
20+
'ap-southeast-2': 's3-website-ap-southeast-2.amazonaws.com',
21+
'ap-northeast-1': 's3-website-ap-northeast-1.amazonaws.com',
22+
'eu-central-1': 's3-website.eu-central-1.amazonaws.com',
23+
'eu-west-1': 's3-website-eu-west-1.amazonaws.com',
24+
'eu-west-2': 's3-website.eu-west-2.amazonaws.com',
25+
'sa-east-1': 's3-website-sa-east-1.amazonaws.com',
26+
}[region])
27+
1028
class Client {
1129
constructor(serverless, options){
1230
this.serverless = serverless;
@@ -284,10 +302,13 @@ class Client {
284302

285303
_uploadFile(filePath) {
286304
let _this = this,
287-
fileKey = filePath.replace(_this.clientPath, '').substr(1).replace(/\\/g, '/');
305+
fileKey = filePath.replace(_this.clientPath, '').substr(1).replace(/\\/g, '/'),
306+
urlRoot = regionToUrlRootMap(_this.region);
288307

289308
this.serverless.cli.log(`Uploading file ${fileKey} to bucket ${_this.bucketName}...`);
290-
this.serverless.cli.log(`If successful this should be deployed at: https://s3.amazonaws.com/${_this.bucketName}/${fileKey}`)
309+
this.serverless.cli.log('If successful this should be deployed at:')
310+
this.serverless.cli.log(`https://${urlRoot}/${_this.bucketName}/${fileKey}`)
311+
this.serverless.cli.log(`http://${_this.bucketName}.${urlRoot}/${fileKey}`)
291312

292313
fs.readFile(filePath, function(err, fileBuffer) {
293314

0 commit comments

Comments
 (0)