Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Main #68

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 58 additions & 60 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,59 @@
const express = require("express");
const express = require('express');
const Color = require('color');
const colorNamer = require('color-namer');

// Inicializar la aplicación
const app = express();
const port = process.env.PORT || 3001;

app.get("/", (req, res) => res.type('html').send(html));

const server = app.listen(port, () => console.log(`Example app listening on port ${port}!`));

server.keepAliveTimeout = 120 * 1000;
server.headersTimeout = 120 * 1000;

const html = `
<!DOCTYPE html>
<html>
<head>
<title>Hello from Render!</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
<script>
setTimeout(() => {
confetti({
particleCount: 100,
spread: 70,
origin: { y: 0.6 },
disableForReducedMotion: true
});
}, 500);
</script>
<style>
@import url("https://p.typekit.net/p.css?s=1&k=vnd5zic&ht=tk&f=39475.39476.39477.39478.39479.39480.39481.39482&a=18673890&app=typekit&e=css");
@font-face {
font-family: "neo-sans";
src: url("https://use.typekit.net/af/00ac0a/00000000000000003b9b2033/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("woff2"), url("https://use.typekit.net/af/00ac0a/00000000000000003b9b2033/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("woff"), url("https://use.typekit.net/af/00ac0a/00000000000000003b9b2033/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("opentype");
font-style: normal;
font-weight: 700;
}
html {
font-family: neo-sans;
font-weight: 700;
font-size: calc(62rem / 16);
}
body {
background: white;
}
section {
border-radius: 1em;
padding: 1em;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<section>
Hello from Render!
</section>
</body>
</html>
`

// Definir el puerto en el que el servidor escuchará
const port = process.env.PORT || 3000;

// Mapa de traducción de nombres de colores al español
const colorTranslations = {
"red": "Rojo",
"green": "Verde",
"blue": "Azul",
"black": "Negro",
"white": "Blanco",
"yellow": "Amarillo",
"orange": "Naranja",
"pink": "Rosa",
"purple": "Púrpura",
"brown": "Marrón",
"gray": "Gris",
"cyan": "Cian",
"magenta": "Magenta",
// Agrega más traducciones según sea necesario
};

// Crear el endpoint para la raíz
app.get('/', (req, res) => {
res.send('Bienvenido a la API de conversión de colores. Usa /color?hex=tu_codigo_hexadecimal para obtener el nombre del color.');
});

// Crear el endpoint para manejar la conversión de color
app.get('/color', (req, res) => {
let hex = req.query.hex;

try {
// Convertir cualquier longitud de código hexadecimal a un formato de 6 dígitos
const color = Color(`#${hex}`).hex().slice(1); // Eliminar el prefijo '#'

// Convertir el código hexadecimal al nombre del color
const namedColors = colorNamer(color);
const colorNameInEnglish = namedColors.basic[0].name;

// Traducir el nombre del color al español
const colorNameInSpanish = colorTranslations[colorNameInEnglish.toLowerCase()] || colorNameInEnglish;

// Devolver el nombre del color como respuesta
res.send(`${colorNameInSpanish}`);
} catch (error) {
res.status(400).send('Código hexadecimal inválido');
}
});

// Iniciar el servidor
app.listen(port, () => {
console.log(`Servidor corriendo en http://localhost:${port}`);
});