Skip to content

Instantly share code, notes, and snippets.

@wwymak
Created January 27, 2016 10:31
Show Gist options
  • Save wwymak/7d2e6ba479f7b68716f3 to your computer and use it in GitHub Desktop.
Save wwymak/7d2e6ba479f7b68716f3 to your computer and use it in GitHub Desktop.
basic node/express setup so you can easily do api requests
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-preset-es2015": "^6.3.13",
"body-parser": "^1.14.2",
"express": "^4.13.4",
"method-override": "^2.3.5",
"morgan": "^1.6.1",
"request": "^2.67.0",
"serve-favicon": "^2.3.0",
}
}
var express = require('express');
var router = express.Router();
var request = require('request');
var apibaseURL = "http://vb.api.ow.zoocha.com";
router.get('/' , function (req, res) {
console.log("getting base indexhtml");
res.sendFile(__base + 'index.html'); // load the single view file (angular will handle the page changes on the front-end)
});
router.get('/api/url', function(req, res) {
var url = req.param('apiURL');
var outurl = apibaseURL + url;
console.log(url, outurl)
req.pipe(request(outurl)).pipe(res);
});
module.exports = function(app){
app.use('/' ,router);
}
var express = require('express');
var app = express();
var morgan = require('morgan');
var favicon = require('serve-favicon');
var bodyParser = require('body-parser');
var port = process.env.PORT || 8080;
var methodOverride = require('method-override');
global.__base = __dirname + '/';
// configuration ===============================================================
//where are your js, css etc files
app.use(express.static(__dirname + '/dest')); // set the static files location /public/img will be /img for users
//app.use(favicon(__dirname + '/public/images/favicon.png'));
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({'extended':'false'})); //
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
app.use(methodOverride());
// routes ======================================================================
require(__dirname + '/routes.js')(app);
//server startup
app.listen(port);
console.log("app listening on port 8080");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment