Last active
August 29, 2015 14:16
-
-
Save d1egoaz/ccbba154a39fad70e647 to your computer and use it in GitHub Desktop.
simple node express example
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
var express = require('express'); | |
var request = require('request'); | |
var app = express(); | |
app.all('*', function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
next(); | |
}); | |
app.get('/proxy/:token?', function (req, res) { | |
var j={"name":"d1egoaz"}; | |
res.json(j); | |
}); | |
app.get('/proxy2/:token?', function (req, res) { | |
res.statusCode = 404; | |
return res.send('Error 404: Not found proxy2'); | |
}); | |
app.listen(9042); | |
// test | |
// curl http://localhost:9042/proxy/testtoken Res: HTTP 200, {"name":"d1egoaz"} | |
// curl http://localhost:9042/proxy2/testtoken Res: HTTP 400, Error 404: Not found proxy2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment