-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
53 lines (43 loc) · 1.29 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
47
48
49
50
51
52
53
const {Lambda} = require('aws-sdk');
const fetch = require('node-fetch');
const {getResponse} = require('./functions');
exports.handler = async (event) => {
const lambda = new Lambda();
const plugin = event.pathParameters.plugin || '';
const validPlugins = {
'bluehost-wordpress-plugin': {
vendorName: 'bluehost',
packageName: 'bluehost-wordpress-plugin',
pluginBasename: 'bluehost-wordpress-plugin/bluehost-wordpress-plugin.php'
},
'mojo-marketplace-wp-plugin': {
vendorName: 'mojoness',
packageName: 'mojo-marketplace-wp-plugin',
pluginBasename: 'mojo-marketplace-wp-plugin/mojo-marketplace.php'
}
};
if (!plugin || !validPlugins.hasOwnProperty(plugin)) {
return {
statusCode: 400,
body: JSON.stringify('Invalid plugin!'),
};
}
const response = await fetch(
`https://bluehost-wp-release.com/v1/?vendorName=${ validPlugins[plugin]['vendorName'] }&packageName=${ validPlugins[plugin]['packageName'] }&pluginBasename=${ validPlugins[plugin]['pluginBasename'] }`,
{method: 'GET'}
);
// Proxy error response
if (response.status !== 200) {
return getResponse({
statusCode: response.status,
body: await response.json(),
});
}
const {package: Location} = await response.json();
return getResponse({
statusCode: 302,
headers: {
Location
},
});
};