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
//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 |
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
databaseURI = process.env.PERSON_MONGOLAB_CONNECTION; | |
var db = mongojs(databaseURI, collections, {authMechanism: 'ScramSHA1'}); |
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
// 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); | |
} |
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
<!--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">×</button> | |
<h4 class="modal-title">Edit Person</h4> | |
</div> |
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
<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> | |
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
<!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"> |
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 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()); |
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
'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) { |
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
//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); |
NewerOlder