Last active
September 29, 2021 16:19
-
-
Save Dylan0916/dac6a691ab3dcc690b279a5f540882ea to your computer and use it in GitHub Desktop.
基本的 dynamic links 生成 code
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
const axios = require("axios"); | |
const headers = { | |
"Access-Control-Allow-Headers": "Content-Type", | |
"Access-Control-Allow-Origin": "*", | |
"Access-Control-Allow-Methods": "OPTIONS,POST,GET", | |
} | |
exports.handler = async (event) => { | |
const queryString = event.queryStringParameters || {}; | |
const { link } = queryString; | |
const POST_URL = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=your_key"; | |
const config = { | |
dynamicLinkInfo: { | |
domainUriPrefix: "https://xxx.page.link", | |
link, | |
}, | |
}; | |
const axiosResp = await axios.post(POST_URL, config); | |
const dynamicLink = axiosResp.data.shortLink; | |
const response = { | |
statusCode: 200, | |
headers, | |
body: JSON.stringify({ link: dynamicLink }), | |
}; | |
return response; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment