Skip to content

Instantly share code, notes, and snippets.

@d1egoaz d1egoaz/nodeMock.js
Last active Aug 29, 2015

Embed
What would you like to do?
simple node express example
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
You can’t perform that action at this time.