Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit 5a8b8a7

Browse files
author
Chandra Pratap
authored
initial commit (#281)
1 parent 2c6240f commit 5a8b8a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+15384
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
################################################
2+
############### .gitignore ##################
3+
################################################
4+
#
5+
# This file is only relevant if you are using git.
6+
#
7+
# Files which match the splat patterns below will
8+
# be ignored by git. This keeps random crap and
9+
# sensitive credentials from being uploaded to
10+
# your repository. It allows you to configure your
11+
# app for your machine without accidentally
12+
# committing settings which will smash the local
13+
# settings of other developers on your team.
14+
#
15+
# Some reasonable defaults are included below,
16+
# but, of course, you should modify/extend/prune
17+
# to fit your needs!
18+
################################################
19+
20+
21+
22+
23+
################################################
24+
# Local Configuration
25+
#
26+
# Explicitly ignore files which contain:
27+
#
28+
# 1. Sensitive information you'd rather not push to
29+
# your git repository.
30+
# e.g., your personal API keys or passwords.
31+
#
32+
# 2. Environment-specific configuration
33+
# Basically, anything that would be annoying
34+
# to have to change every time you do a
35+
# `git pull`
36+
# e.g., your local development database, or
37+
# the S3 bucket you're using for file uploads
38+
# development.
39+
#
40+
################################################
41+
42+
config/local.js
43+
44+
45+
46+
47+
48+
################################################
49+
# Dependencies
50+
#
51+
# When releasing a production app, you may
52+
# consider including your node_modules and
53+
# bower_components directory in your git repo,
54+
# but during development, its best to exclude it,
55+
# since different developers may be working on
56+
# different kernels, where dependencies would
57+
# need to be recompiled anyway.
58+
#
59+
# More on that here about node_modules dir:
60+
# http://www.futurealoof.com/posts/nodemodules-in-git.html
61+
# (credit Mikeal Rogers, @mikeal)
62+
#
63+
# About bower_components dir, you can see this:
64+
# http://addyosmani.com/blog/checking-in-front-end-dependencies/
65+
# (credit Addy Osmani, @addyosmani)
66+
#
67+
################################################
68+
69+
node_modules
70+
bower_components
71+
72+
73+
74+
75+
################################################
76+
# Sails.js / Waterline / Grunt
77+
#
78+
# Files generated by Sails and Grunt, or related
79+
# tasks and adapters.
80+
################################################
81+
.tmp
82+
dump.rdb
83+
84+
85+
86+
87+
88+
################################################
89+
# Node.js / NPM
90+
#
91+
# Common files generated by Node, NPM, and the
92+
# related ecosystem.
93+
################################################
94+
lib-cov
95+
*.seed
96+
*.log
97+
*.out
98+
*.pid
99+
npm-debug.log
100+
101+
102+
103+
104+
105+
################################################
106+
# Miscellaneous
107+
#
108+
# Common files generated by text editors,
109+
# operating systems, file systems, etc.
110+
################################################
111+
112+
*~
113+
*#
114+
.DS_STORE
115+
.netbeans
116+
nbproject
117+
.idea
118+
.node_history
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"generators": {
3+
"modules": {}
4+
}
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:8
2+
LABEL maintainer="Azure App Service Container Images <[email protected]>"
3+
4+
# Create app directory
5+
WORKDIR /app
6+
7+
# Bundle app source
8+
COPY . .
9+
RUN npm install
10+
11+
EXPOSE 3000 80
12+
CMD [ "npm", "start" ]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Gruntfile
3+
*
4+
* This Node script is executed when you run `grunt` or `sails lift`.
5+
* It's purpose is to load the Grunt tasks in your project's `tasks`
6+
* folder, and allow you to add and remove tasks as you see fit.
7+
* For more information on how this works, check out the `README.md`
8+
* file that was generated in your `tasks` folder.
9+
*
10+
* WARNING:
11+
* Unless you know what you're doing, you shouldn't change this file.
12+
* Check out the `tasks` directory instead.
13+
*/
14+
15+
module.exports = function(grunt) {
16+
17+
18+
// Load the include-all library in order to require all of our grunt
19+
// configurations and task registrations dynamically.
20+
var includeAll;
21+
try {
22+
includeAll = require('include-all');
23+
} catch (e0) {
24+
try {
25+
includeAll = require('sails/node_modules/include-all');
26+
} catch (e1) {
27+
console.error('Could not find `include-all` module.');
28+
console.error('Skipping grunt tasks...');
29+
console.error('To fix this, please run:');
30+
console.error('npm install include-all --save`');
31+
console.error();
32+
33+
grunt.registerTask('default', []);
34+
return;
35+
}
36+
}
37+
38+
39+
/**
40+
* Loads Grunt configuration modules from the specified
41+
* relative path. These modules should export a function
42+
* that, when run, should either load/configure or register
43+
* a Grunt task.
44+
*/
45+
function loadTasks(relPath) {
46+
return includeAll({
47+
dirname: require('path').resolve(__dirname, relPath),
48+
filter: /(.+)\.js$/,
49+
excludeDirs: /^\.(git|svn)$/
50+
}) || {};
51+
}
52+
53+
/**
54+
* Invokes the function from a Grunt configuration module with
55+
* a single argument - the `grunt` object.
56+
*/
57+
function invokeConfigFn(tasks) {
58+
for (var taskName in tasks) {
59+
if (tasks.hasOwnProperty(taskName)) {
60+
tasks[taskName](grunt);
61+
}
62+
}
63+
}
64+
65+
66+
67+
// Load task functions
68+
var taskConfigurations = loadTasks('./tasks/config'),
69+
registerDefinitions = loadTasks('./tasks/register');
70+
71+
// (ensure that a default task exists)
72+
if (!registerDefinitions.default) {
73+
registerDefinitions.default = function(grunt) {
74+
grunt.registerTask('default', []);
75+
};
76+
}
77+
78+
// Run task functions to configure Grunt.
79+
invokeConfigFn(taskConfigurations);
80+
invokeConfigFn(registerDefinitions);
81+
82+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var dbOperations = require('../helpers/databaseOperations.js');
2+
3+
module.exports = {
4+
showHomepageWithCosmosDBOperations: async function (req, res) {
5+
dbOperations.addRecord("index", function () {
6+
dbOperations.queryCount(function (count) {
7+
res.view('homepage', {
8+
visitCount: count
9+
});
10+
}, function (error) {
11+
res.view('500', {
12+
data: error
13+
});
14+
});
15+
}, function (error) {
16+
res.view('500', {
17+
data: error
18+
});
19+
});
20+
}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
users: async function (req, res) {
3+
res.send("respond with a resource");
4+
}
5+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
var MongoClient = require("mongodb").MongoClient;
2+
var fs = require('fs');
3+
var obj = {
4+
"databaseName": "sampledatabase",
5+
"collectionName": "samplecollection"
6+
};
7+
8+
var connectionString = "mongodb://account:[email protected]:10255/?ssl=true";
9+
if(process.env.NODE_ENV == "production"){
10+
var connectionString = process.env.connectionString;
11+
var stringSplit1 = connectionString.split("://")[1];
12+
var stringSplit2 = stringSplit1.split('@');
13+
var userNamePassword = stringSplit2[0];
14+
userNamePassword = userNamePassword.split(':');
15+
var userName = userNamePassword[0];
16+
var password = userNamePassword[1];
17+
var databaseName = obj.databaseName;
18+
var collectionName = obj.collectionName;
19+
connectionString = ("mongodb://" + encodeURIComponent(userName) + ":" + encodeURIComponent(password) + "@" + stringSplit2[1]);
20+
}
21+
else{
22+
MongoClient = {
23+
connect: function(connectionString, options, callback){
24+
var client = {
25+
db: function(databaseName){
26+
var testDB = {
27+
collection: function(collectionName){
28+
var testCollection = {
29+
count: function(callback){
30+
callback(null, "unittest");
31+
},
32+
insertMany: function(items, callback){
33+
callback(null, "success");
34+
}
35+
}
36+
return testCollection;
37+
}
38+
}
39+
return testDB;
40+
},
41+
close: function(){
42+
43+
}
44+
}
45+
callback(null, client);
46+
}
47+
};
48+
}
49+
50+
module.exports = {
51+
52+
queryCount: function (callback, errorCallback) {
53+
console.log(`Querying container:\n${collectionName}`);
54+
MongoClient.connect(connectionString, { useNewUrlParser: true }, function (err, client) {
55+
if (err != null) {
56+
errorCallback(err);
57+
return;
58+
}
59+
console.log("Connected correctly to server");
60+
var db = client.db(databaseName);
61+
// Get the documents collection
62+
const collection = db.collection(collectionName);
63+
// Find some documents
64+
collection.count(function (err, count) {
65+
if (err != null) {
66+
errorCallback(err)
67+
}
68+
console.log(`Found ${count} records`);
69+
callback(count);
70+
client.close();
71+
});
72+
});
73+
},
74+
75+
addRecord: function (pageName, callback, errorCallback) {
76+
var milliseconds = (new Date).getTime().toString();
77+
var itemBody = {
78+
"id": milliseconds,
79+
"page": pageName
80+
};
81+
MongoClient.connect(connectionString, { useNewUrlParser: true }, function (err, client) {
82+
if (err != null) {
83+
errorCallback(err);
84+
return;
85+
}
86+
console.log("Connected correctly to server");
87+
var db = client.db(databaseName);
88+
// Get the documents collection
89+
const collection = db.collection(collectionName);
90+
// Insert some documents
91+
collection.insertMany([itemBody], function (err, result) {
92+
if (err != null) {
93+
errorCallback(err)
94+
}
95+
callback();
96+
client.close();
97+
});
98+
});
99+
}
100+
}

github/node/sail.js/containerCosmosDBWithTests/Application/api/models/.gitkeep

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* sessionAuth
3+
*
4+
* @module :: Policy
5+
* @description :: Simple policy to allow any authenticated user
6+
* Assumes that your login action in one of your controllers sets `req.session.authenticated = true;`
7+
* @docs :: http://sailsjs.org/#!/documentation/concepts/Policies
8+
*
9+
*/
10+
module.exports = function(req, res, next) {
11+
12+
// User is allowed, proceed to the next policy,
13+
// or if this is the last policy, the controller
14+
if (req.session.authenticated) {
15+
return next();
16+
}
17+
18+
// User is not allowed
19+
// (default res.forbidden() behavior can be overridden in `config/403.js`)
20+
return res.forbidden('You are not permitted to perform this action.');
21+
};

0 commit comments

Comments
 (0)