Untitled
unknown
plain_text
a year ago
949 B
10
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