Skip to content

Instantly share code, notes, and snippets.

@snowfluke
Last active October 16, 2022 13:47
Show Gist options
  • Save snowfluke/1fd78135db6b362d8855392003c05151 to your computer and use it in GitHub Desktop.
Save snowfluke/1fd78135db6b362d8855392003c05151 to your computer and use it in GitHub Desktop.
A firend's code to refactor
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