This file contains 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
module.exports = function() { | |
var justin = { | |
removeKeys: function(keys, obj) { | |
var newObj = {}; | |
for (var i = 0; i < _.keys(obj).length; i++) { | |
var key = _.keys(obj)[i]; | |
if (_.keys(obj).indexOf(key) == -1) { | |
newObj[key] = obj[key]; | |
} |
This file contains 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
module.exports = function preflightApi(){ | |
return function preflightApi(req, res, next){ | |
//this is where the magic happens | |
res.header('Access-Control-Allow-Origin', '*'); | |
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS'); | |
res.header('Access-Control-Allow-Headers', 'User-Agent, Accept-Language, Accept-Encoding, Accept-Charset, Connection, Content-Length, Origin, Pragma, Accept-Charset, Cache-Control, Accept, Content-Type, Sessionid'); | |
res.header('Access-Control-Max-Age', '1000'); | |
This file contains 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 http = require('http'); | |
var sys = require('sys') | |
var exec = require('child_process').exec; | |
http.createServer(function (req, res) { | |
var header=req.headers['authorization']||'', // get the header | |
token=header.split(/\s+/).pop()||'', // and the encoded auth token | |
auth=new Buffer(token, 'base64').toString(), // convert from base64 | |
parts=auth.split(/:/), // split on colon | |
username=parts[0], | |
password=parts[1]; |
This file contains 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
So you want to build a HTML Webapp and then query your JSON Api. To avoid cross domain calls use NGINX to proxy only certain requests to the API. In my case I use the Accept: header from the HTTP request to specify return data format. If that format is application/json send it to the api, otherwise try to serve the static html. |
This file contains 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
<?php | |
//would be controllers/pg.php | |
class pg extends Controller { | |
var $pgItem; | |
var $parentPage; | |
function pg() { | |
//do some constructor related stuff here | |
} | |
function permalink($segments) { |
This file contains 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
The two files attached are Express Middleware | |
Srvformat sets the format based on the accept header | |
to switch it to api mode. | |
ApiSession uses the req.format set by this to decide | |
which kinds of sessions to use. |
This file contains 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
/*! | |
* Express - Resource | |
* Copyright(c) 2010-2011 TJ Holowaychuk <[email protected]> | |
* Copyright(c) 2011 Daniel Gasienica <[email protected]> | |
* MIT Licensed | |
*/ | |
/** | |
* Module dependencies. |
This file contains 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
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$.ajax("http://revolve.amazon/session/create", { | |
type: "POST", | |
dataType: "json", | |
processData: false, | |
headers: { | |
"Accept": "application/json", |
This file contains 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
$.fn.serializeObject = function() | |
{ | |
var o = {}; | |
var a = this.serializeArray(); | |
$.each(a, function() { | |
var oldName = this.name; | |
this.name = this.name.replace(/\[\]/g, ''); | |
if (this.name.indexOf('[') >= 0) { | |
var innerName = this.name.match(/.*\[(.*)\]/)[1]; |
This file contains 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
#!/bin/sh | |
pid=`ps aux | grep -i "/path/to/app/as/started" | grep -v "grep" | awk '{print $2}'` | |
kill $pid |
OlderNewer