Skip to content

Commit

Permalink
SP Trans mark on 1036
Browse files Browse the repository at this point in the history
  • Loading branch information
Herman A. Junge committed Jun 28, 2011
1 parent 16d33d3 commit 4a7801b
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 247 deletions.
30 changes: 18 additions & 12 deletions code-es/aplicacion/requestHandlers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// requestHandlers.js
// Ejemplo de NodeBeginner
// Se intenta traducir al máximo al Español,
// sin embargo, con el fin de preservar el sentido, se dejan
// algunas variables en inglés.

var querystring = require("querystring"),
fs = require("fs"),
formidable = require("formidable");

function inicio(response) {
function iniciar(response) {
console.log("Manipulador de Peticion para 'inicio' fue llamado.");

var body = '<html>'+
Expand All @@ -22,36 +28,36 @@ function inicio(response) {
response.end();
}

function upload(response, request) {
console.log("Request handler 'upload' was called.");
function subir(response, request) {
console.log("Manipulador de Peticion para 'subir' fue llamado.");

var form = new formidable.IncomingForm();
console.log("about to parse");
console.log("A punto de parsear");
form.parse(request, function(err, fields, files) {
console.log("parsing done");
console.log("parseo hecho");
fs.renameSync(files.upload.path, "/tmp/test.png");
response.writeHead(200, {"Content-Type": "text/html"});
response.write("received image:<br/>");
response.write("imagen recibida:<br/>");
response.write("<img src='/show' />");
response.end();
});
}

function show(response) {
console.log("Request handler 'show' was called.");
function mostrar(response) {
console.log("Manipulador de Peticion para 'mostrar' fue llamado.");
fs.readFile("/tmp/test.png", "binary", function(error, file) {
if(error) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write(err + "\n");
response.end();
} else {
response.writeHead(200, {"Content-Type": "image/png"});
response.write(file, "binary");
response.write(file, "binario");
response.end();
}
});
}

exports.start = start;
exports.upload = upload;
exports.show = show;
exports.iniciar = iniciar;
exports.subir = subir;
exports.mostrar = mostrar;
14 changes: 12 additions & 2 deletions code-es/aplicacion/router.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// router.js
// Ejemplo de NodeBeginner
// Se intenta traducir al máximo al Español,
// sin embargo, con el fin de preservar el sentido, se dejan
// algunas variables en inglés.

function route(handle, pathname, response, request) {

// Ojo! A node.js no le gustan los strings con acentos
// No he probado los character entities a ver si ayudan aca.
console.log("A punto de rutear una peticion para " + pathname);
if (typeof handle[pathname] === 'function') {
handle[pathname](response, request);
} else {
}
else {
console.log("No hay manipulador de peticion para " + pathname);
response.writeHead(404, {"Content-Type": "text/html"});
response.write("404 No Encontrado");
response.end();
}
}

exports.route = route;
exports.route = route;
14 changes: 13 additions & 1 deletion code-es/aplicacion/server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// server.js
// Ejemplo de NodeBeginner
// Se intenta traducir al máximo al Español,
// sin embargo, con el fin de preservar el sentido, se dejan
// algunas variables en inglés.

var http = require("http");
var url = require("url");

// se opta por mantener los verbos route y handle
// que significan, respectivamente, rutear y manipular
function iniciar(route, handle) {

function onRequest(request, response) {

// pathname es el nombre de la ruta
// ej: http://dominio/pathname/to/myfile.htm
var pathname = url.parse(request.url).pathname;
console.log("Peticion para " + pathname + " recibida.");
route(handle, pathname, response, request);
Expand All @@ -12,4 +24,4 @@ function iniciar(route, handle) {
console.log("Servidor Iniciado.");
}

exports.start = start;
exports.iniciar = iniciar;
Loading

0 comments on commit 4a7801b

Please sign in to comment.