Skip to content

Instantly share code, notes, and snippets.

View nikmartin's full-sized avatar

Nik Martin nikmartin

View GitHub Profile
@nikmartin
nikmartin / gist:9004005
Created February 14, 2014 16:18
Node + Express Cache Control
var ONE_DAY = 86400000;
app.use(function (req, res, next) {
res.setHeader('Expires', new Date(Date.now() + ONE_DAY).toUTCString());
res.header('X-powered-by', 'Super Awesome Server');
next();
});
@nikmartin
nikmartin / conf.d-myapp.conf
Created February 12, 2014 17:03
Nginx proxy for Node.js App
# HTTPS server
#
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name localhost;
"use strict";
module.exports = function () {
return function (req, res, next) {
//do stuff here
debug("NEEEXT!");
return res.end();
@nikmartin
nikmartin / server.js
Last active December 19, 2015 13:29
Simple node.js web server - Now even simpler!
1. Create a directory, and cd to it:
~/myserver> mkdir myserver && cd myserver
2. install send:
~/myserver> npm install send
3. Create your server:
~/myserver> cat > server.js << EOF
"use strict";
var http = require('http'),
send = require('send'),
@nikmartin
nikmartin / A: Secure Sessions Howto
Last active April 7, 2024 21:56
Secure sessions with Node.js, Express.js, and NginX as an SSL Proxy
Secure sessions are easy, but not very well documented.
Here's a recipe for secure sessions in Node.js when NginX is used as an SSL proxy:
The desired configuration for using NginX as an SSL proxy is to offload SSL processing
and to put a hardened web server in front of your Node.js application, like:
[NODE.JS APP] <- HTTP -> [NginX] <- HTTPS -> [PUBLIC INTERNET] <-> [CLIENT]
Edit for express 4.X and >: Express no longer uses Connect as its middleware framework, it implements its own now.
{"posts":[
{ "title": "title1", "date": "03-21-2013" },
{ "title": "title2", "date": "03-21-2013" },
{ "title": "title3", "date": "03-21-2013" },
{ "title": "title4", "date": "03-21-2013" }]
}
@nikmartin
nikmartin / gist:3835175
Created October 4, 2012 17:36
fusion provision
<?php
$fh = fopen("/var/www/fusionpbx/aastra/nik.foo","w") or die("Unable to write. Make sure the path exists and permissons are set correctly.");
fwrite($fh, "shit on my driveway again, butthole");
fclose($fh);
?>
@nikmartin
nikmartin / corosync.conf
Created September 26, 2012 13:48
corosync crash
compatibility: whitetank
totem {
version: 2
secauth: off
threads: 0
interface {
ringnumber: 0
bindnetaddr: 172.16.10.0
mcastaddr: 226.94.1.2
@nikmartin
nikmartin / gist:3785046
Created September 25, 2012 23:23
corosync crash
valgrind corosync -f
==2796== Memcheck, a memory error detector
==2796== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==2796== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info
==2796== Command: corosync -f
==2796==
==2796== Invalid write of size 2
==2796== at 0x4E35F1A: totemip_parse (in /usr/lib64/libtotem_pg.so.4.0.0)
==2796== by 0x40B36E: totem_config_read (in /usr/sbin/corosync)
==2796== by 0x40674D: main (in /usr/sbin/corosync)
@nikmartin
nikmartin / chkauth.c
Created September 10, 2012 00:26
PAM Auth App
#include <security/pam_appl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct pam_response *reply;
int null_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) {
*resp = reply;