Created
August 9, 2013 19:19
-
-
Save netogallo/6196376 to your computer and use it in GitHub Desktop.
Kaiser Buenote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Vos copia esto | |
var express = require('express') | |
, http = require('http') | |
, path = require('path'); | |
//Creas una web app | |
var app = express(); | |
//localhost:2000/test?arg=5&numero=hola | |
var getTest = function(req,res){ | |
var arg1 = req.param('arg'); //agr1 = 5 | |
var loqmellego = req.param('numero'); //loqmellego = 'hola' | |
res.write(loqmellego); | |
res.write(req.param('arg')); | |
res.end(); | |
} | |
var basedatos = {}; | |
//localhost:3000/guardar?user=neto&lat=5&long=8 | |
var guardarPos = function(req,res){ | |
var user = req.param('user'); | |
var lat = req.param('lat'); | |
var long = req.param('long'); | |
basedatos[user] = {lat : lat,long:long}; | |
res.write('Good'); | |
res.end(); | |
} | |
//localhost:3000/get?user=neto | |
var getPos = function(req,res){ | |
var pos = basedatos[req.param('user')]; | |
res.json(pos); | |
res.end(); | |
} | |
var formulario = function(req,res){ | |
var body = '<html><head></head><body><form method="POST" action="/guardarPos"><input type="text" name="user"/><br><input type="text" name="lat"/><br/><input type="text" name="long"/><input type="submit"/></form></body></html>'; | |
res.writeHead(200, { | |
'Content-Length': body.length, | |
'Content-Type': 'text/html' }); | |
res.write(body); | |
res.end(); | |
} | |
//Config basica | |
app.configure(function(){ | |
app.set('port', process.env.PORT || 2000); | |
app.use(express.favicon()); | |
app.use(express.logger('dev')); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(app.router); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
}); | |
app.configure('development', function(){ | |
app.use(express.errorHandler()); | |
}); | |
app.get('/test', getTest); | |
app.get('/guardarPos',guardarPos); | |
app.post('/guardarPos',guardarPos); | |
app.get('/get',getPos); | |
app.get('/form',formulario); | |
var server = http.createServer(app); | |
server.listen(app.get('port'), function(){ | |
console.log("Express server listening on port " + app.get('port')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment