Skip to content

Instantly share code, notes, and snippets.

View bmdayal's full-sized avatar
🏠
Working from home

Brij Mohan bmdayal

🏠
Working from home
View GitHub Profile
//CORS on ExpressJS: http://enable-cors.org/server_expressjs.html
//Add headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://addressbookclient.azurewebsites.net');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
@bmdayal
bmdayal / DBConfig.js
Created November 2, 2015 22:30
Part of server.js in node Addressbook sample application
databaseURI = process.env.PERSON_MONGOLAB_CONNECTION;
var db = mongojs(databaseURI, collections, {authMechanism: 'ScramSHA1'});
// Retrieve
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mongodb://mongolabtest:mongolabtest@ds048368.mongolab.com:48368/MongoLab-3", function(err, db) {
if(!err) {
console.log("We are connected");
} else {
console.log(err);
}
<!--Edit person modal-->
<div id="personEditModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit Person</h4>
</div>
<table class="table table-striped table-bordered">
<thead>
<tr class='danger'>
<td>Name</td>
<td>Email</td>
<td>Number</td>
<td>Edit</td>
<td>Delete</td>
</tr>
@bmdayal
bmdayal / index.html
Created October 18, 2015 15:55
Index page for my blog post example
<!DOCTYPE html>
<html ng-app='addressBookApp'>
<head>
<title>Address Book</title>
<script src="https://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
@bmdayal
bmdayal / server.js
Last active October 18, 2015 15:33
Sample NodeJS server created for my blog
var express = require('express');
var app = express();
var mongojs = require('mongojs');
var db = mongojs('AddressBook', ['Persons']);
var bodyParser = require('body-parser');
app.use(express.static(__dirname));
app.use(bodyParser.json());
'use strict';
(function () {
var addressBookApp = angular.module("addressBookApp");
var PersonCtrl = function ($scope, $http)
{
$scope.working = 'Angular is Working';
//common error function
var onError = function (error) {
//add new person
var onAddPersonCompleted = function(response){
$scope.person = response.data;
console.log(response.data);
refresh();
};
$scope.addPerson = function(person){
$http.post('/addPerson', person)
.then(onAddPersonCompleted, onError);
console.log(person);