Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeiel Lima Miranda committed Sep 20, 2024
1 parent 1f2be81 commit 088cc35
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pages/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,26 @@ export default async function handler(req, res) {
const { name, Telefone, email, cpf, random } = query;

const domain = 'https://my-pix.vercel.app';
const staticUrl = `${domain}/view?name=${encodeURIComponent(name)}&Telefone=${encodeURIComponent(Telefone)}&email=${encodeURIComponent(email)}&cpf=${encodeURIComponent(cpf)}&random=${encodeURIComponent(random)}`;

// Criar um objeto com os parâmetros opcionais
const params = {
name,
Telefone,
email,
cpf,
random
};

// Filtrar parâmetros não fornecidos (undefined ou null) e gerar a query string dinamicamente
const filteredParams = Object.entries(params)
.filter(([key, value]) => value !== undefined && value !== null)
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
.join('&');

// Gera a URL completa para a página estática
const staticUrl = `${domain}/view?${filteredParams}`;

// Faz uma solicitação ao is.gd para encurtar a URL gerada
try {
const response = await fetch(`https://is.gd/create.php?format=simple&url=${encodeURIComponent(staticUrl)}`);
const shortUrl = await response.text();
Expand Down

1 comment on commit 088cc35

@vercel
Copy link

@vercel vercel bot commented on 088cc35 Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

my-pix – ./

my-pix.vercel.app
my-pix-jeiels-projects.vercel.app
my-pix-git-main-jeiels-projects.vercel.app

Please sign in to comment.