Created
August 23, 2019 16:17
-
-
Save phawk/5e47aef501135001c0e443f68a1d7826 to your computer and use it in GitHub Desktop.
Shopify install lambda
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
exports.handler = async (event, context) => { | |
const shop = event.queryStringParameters.shop | |
const redirectUri = event.queryStringParameters.redirect | |
const apiKey = process.env.SHOPIFY_API_KEY | |
const scopes="read_content,write_content,read_products,read_themes,write_themes" | |
if (shop) { | |
const installUrl = 'https://' + shop + | |
'/admin/oauth/authorize?client_id=' + apiKey + | |
'&scope=' + scopes + | |
'&redirect_uri=' + redirectUri | |
return { | |
statusCode: 200, | |
headers: { | |
"Content-Type": "application/json" | |
}, | |
body: JSON.stringify({ | |
redirectTo: installUrl | |
}) | |
} | |
} | |
return { | |
statusCode: 400, | |
body: "Missing shop parameter. Please add ?shop=your-development-shop.myshopify.com to your request" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 13 can be written as, instead: