/** **************************************** | |
* Utility file | |
* mixin.js | |
* @returns [object] | |
*/ | |
function mixinFactory() { | |
var len = arguments.length, | |
i = 0, | |
finalObj = {}; | |
/* Simple, Server-Side String Interpolation | |
* Base on John Resig's Microtemplating: http://ejohn.org/blog/javascript-micro-templating/ | |
* | |
* @param str {String} A string with key or object path in handlebar-like syntax: e.g. {{user.name}} | |
* @param data {Object} The data source with with to grab the key matching values | |
* @return {String} The final string with key-value replacements | |
*/ | |
var safeInterpolate = function safeInterpolate (str, data){ | |
// Create a new function with the template converted into executable code. | |
var fn = new Function("obj", |
// Sample object | |
var mySampleData = { | |
foo: { | |
bar: [ | |
1, | |
2, | |
{ | |
baz: "hello", | |
wut: 2, | |
hi: [7, 8, 9] |
The purpose of this is not to be an exhaustive list or a reference for ES6 features. This is intended to share the interesting ideas that are coming down the pipeline and to explore their intentions.
Factories, and services in angular are singleton by definition. If you want to create a new instance you could always just do something like:
module.factory('myIntanceCreator', function(){
return {
create: function(){
// create your instance here
}
};
I have two instances of Node.js running on my local environment, both with Express. One is the actual application client and the other is a mock API server, which is really nothing more than for me to ping against. The client has a basic model with CRUD object on it. Here's an example of the POST with the issue:
create: function (options) {
return qHttp.request({
"host": "127.0.0.1",
"port": "8000"
"method": "POST",
"path": "/sessions",
You can use these API calls in your code if you need to, but I've actually found them quite useful when on the console in Chrome:
require.defined(moduleId)
- returns true if your moduleId has been defined and is ready for use.
require.specified(moduleId)
- returns true if your moduleId has been listed as a dependency by another defined module. Note that just because this returns true doesn't mean your moduleId is ready to use (don't you just love asynchrony?).
requirejs.s.contexts._.config
- I learned about this from Vernon Kesner. This is technically a "back door/undocumented" call - so it could change or disappear without warning. However it returns a very useful object full of configuration info, see below:
Chrome Console results for requrejs.s.conects._.config
- Don't run as root.
- For sessions, set
httpOnly
(andsecure
totrue
if running over SSL) when setting cookies. - Use the Helmet for secure headers: https://github.com/evilpacket/helmet
- Enable
csrf
for preventing Cross-Site Request Forgery: http://expressjs.com/api.html#csrf - Don't use the deprecated
bodyParser()
and only use multipart explicitly. To avoid multiparts vulnerability to 'temp file' bloat, use thedefer
property andpipe()
the multipart upload stream to the intended destination.
var express = require('express'); | |
var https = require('https'); | |
var http = require('http'); | |
var fs = require('fs'); | |
// This line is from the Node.js HTTPS documentation. | |
var options = { | |
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), | |
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem') | |
}; |