Skip to content

Instantly share code, notes, and snippets.

@devsignite
devsignite / api-website.js
Last active December 19, 2015 03:38
example of node.js api module with express.js error middleware
var mongoose = require("mongoose"),
UserSchema = require('../models/User').Schema;
WebsiteSchema = require('../models/Website').Schema;
Website = require('../models/Website').Model;
module.exports = {
// get > api/website
get: function (req, res, next) {
return Website.find(function (err, websites) {
if (!err) {
CREATE TABLE [dbo].[UserProfile] (
[UserId] INT IDENTITY (1, 1) NOT NULL,
[UserName] NVARCHAR (MAX) NULL,
PRIMARY KEY CLUSTERED ([UserId] ASC)
);
CREATE TABLE [dbo].[webpages_Membership] (
[UserId] INT NOT NULL,
[CreateDate] DATETIME NULL,
[ConfirmationToken] NVARCHAR (128) NULL,
@devsignite
devsignite / CORS.allowed
Created June 20, 2013 02:19
Allow CORS in ExpressJS / NodeJS
//CORS middleware
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', config.allowedDomains);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
//...
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"