Created
August 23, 2019 17:01
-
-
Save phawk/1a410ec6a2f34066538e0141aff49e9d to your computer and use it in GitHub Desktop.
Revisions
-
phawk created this gist
Aug 23, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ const https = require("https") const fetch = require("isomorphic-fetch") const Account = require("./models/account") const authenticated = require("./lib/auth") exports.handler = authenticated(async (event, context) => { const { id: shopId, shopifyToken } = context.account try { const resp = await fetch(`https://${shopId}/admin/api/2019-07/graphql.json`, { method: "POST", headers: { "X-Shopify-Access-Token": shopifyToken, "Accept": "application/json", "Content-Type": "application/json" }, body: event.body, agent: new https.Agent({ ca: require("ssl-root-cas/latest").create() }) }) const text = await resp.text() return { statusCode: resp.status, headers: { "Content-Type": "application/json" }, body: text } } catch(e) { return { statusCode: 400, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ error: "Bad request", message: e.message }) } } })