Last active
October 16, 2022 13:47
-
-
Save snowfluke/1fd78135db6b362d8855392003c05151 to your computer and use it in GitHub Desktop.
A firend's code to refactor
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 Endpoint = process.env.ENDPOINT; | |
const ApiKey = process.env.APIKEY; | |
export default async function handler(req, res) { | |
try { | |
const { username, password } = JSON.parse(req.body); | |
if (req.method !== "POST") return res.status(500).json("Method not allowed"); | |
const { result } = await axios({ | |
method: "post", | |
url: `${Endpoint}/login`, | |
headers: { | |
"Content-Type": "application/json", | |
"API-Key": ApiKey, | |
}, | |
data: { | |
username, | |
password, | |
}, | |
}) | |
res.status(200).json(result.data); | |
} catch (error) { | |
res.status(500).json(error.message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment