Untitled
Anonymous
plain_text
10/02/2024 4:34 PM
1.2 KB
16
Indexable
const http = require("http");
const cursos = require("./cursos");
const servidor = http.createServer((req, res) => {
switch (req.method) {
case GET:
return manejarSolicitudesGET(req, res);
case POST:
return manejarSolicitudesPOST(req, res);
default:
}
const port = 3000;
servidor.listen(port, () =>
console.log(`Servidor corriendo en puerto ${port}`)
);
});
function manejarSolicitudesGET(req, res) {
const path = req.url;
if (path === "/") {
} else if (path === "/cursos") {
return res.end(JSON.stringify(cursos.infoCursos));
}
}
function manejarSolicitudesPOST(req, res) {
const path = req.url;
if (path === "/") {
} else if (path === "/cursos/programacion") {
let body = "";
req.on("data", (content) => {
body += content.toString();
});
req.on("end", () => {
body = JSON.parse(body);
});
return res.end("Procesamiento POST finalizado");
}
}
Editor is loading...
Leave a Comment