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

Commit 804cd14

Browse files
committed
initial code
0 parents  commit 804cd14

File tree

331 files changed

+14103
-0
lines changed

Some content is hidden

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

331 files changed

+14103
-0
lines changed

api_server/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.DS_Store

api_server/.jshintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
README*
3+
*.sh

api_server/.jshintrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"node": true,
3+
"esversion": 6,
4+
"curly": true,
5+
"eqeqeq": true,
6+
"forin": true,
7+
"freeze": true,
8+
"latedef": true,
9+
"maxdepth": 4,
10+
"maxparams": 6,
11+
"maxstatements": 20,
12+
"undef": true,
13+
"unused": true
14+
}
15+
16+

api_server/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is obsolete ... please see https://github.com/pkt4dev/dev_tools for instructions on how to get started
2+
# Then install, configure, and load a mongo sandbox and an API server sandbox and go to town

api_server/README.pubnub

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
We currently have a demo subscription
2+
3+
https://admin.pubnub.com
4+
5+
6+
password: pkt4Rocks
7+
8+
publish key: pub-c-b65a2340-6854-4bf2-9ab4-ed971aea9dd4
9+
subscribe key: sub-c-12519fba-c8a0-11e6-8164-0619f8945a4f
10+
secret: sec-c-NmFkMzAyM2YtMGI2MC00ZDU2LWFmZDgtMTE1Y2FmODQ5YTEy

api_server/README.quick_test

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Quick set of curl commands you can do to do very quickly test the api server
2+
3+
# Register new user using email
4+
curl -X PUT "https://127.0.0.1:11079/no-auth/register" -H "Content-Type: application/json" -d '{"email": "[email protected]"}' -k
5+
6+
# Returns something like this:
7+
{
8+
"_id":"587ea812bc2dbeda10681729",
9+
"email":"[email protected]",
10+
"searchable_email":"[email protected]",
11+
"deactivated":false,
12+
"created_at":1484695570743,
13+
"modified_at":1484695570743,
14+
"creator_id":"587ea812bc2dbeda10681729",
15+
"was_created":true,
16+
"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNTg3ZWE4MTJiYzJkYmVkYTEwNjgxNzI5IiwiaWF0IjoxNDg0Njk1NTcwfQ.cKhQRvsDsQT2sj4jcB6sUvWhjpDSKrhQwxbAp0M0ghw"
17+
}
18+
19+
# Grab the access_token and use it for authorization in the header of the next request...
20+
# Create a post
21+
curl -X POST "https://127.0.0.1:12079/post" -H "Content-Type: application/json" -d '{"text": "hello"}' -k -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNTg3ZWE4MTJiYzJkYmVkYTEwNjgxNzI5IiwiaWF0IjoxNDg0Njk1NTcwfQ.cKhQRvsDsQT2sj4jcB6sUvWhjpDSKrhQwxbAp0M0ghw"
22+
23+
# Returns something like this:
24+
{
25+
"_id":"587ea837bc2dbeda1068172a",
26+
"text":"hello",
27+
"creator_id":"587ea812bc2dbeda10681729",
28+
"deactivated":false,
29+
"created_at":1484695607569,
30+
"modified_at":1484695607569
31+
}
32+
33+

api_server/bin/api_server.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
var API_Cluster = require(process.env.CI_API_TOP + '/lib/api_server/api_cluster.js');
5+
var Config_Directory = process.env.CI_API_TOP + '/config';
6+
var Module_Directory = process.env.CI_API_TOP + '/services/api/modules';
7+
var Express_Config = require(Config_Directory + '/express.js');
8+
var Mongo_Config = require(Config_Directory + '/mongo.js');
9+
var Secrets_Config = require(Config_Directory + '/secrets.js');
10+
var PubNub_Config = require(Config_Directory + '/pubnub.js');
11+
var Logger_Config = require(Config_Directory + '/logger.js');
12+
var Email_Config = require(Config_Directory + '/email.js');
13+
var Limits = require(Config_Directory + '/limits.js');
14+
var Version = require(Config_Directory + '/version.js');
15+
var Simple_File_Logger = require(process.env.CI_API_TOP + '/lib/util/simple_file_logger');
16+
17+
var Logger = new Simple_File_Logger(Logger_Config);
18+
19+
if (Mongo_Config.query_logging) {
20+
Object.assign(Mongo_Config.query_logging, Logger_Config, Mongo_Config.query_logging);
21+
}
22+
23+
var data_collections = {
24+
users: require(Module_Directory + '/users/user'),
25+
companies: require(Module_Directory + '/companies/company'),
26+
teams: require(Module_Directory + '/teams/team'),
27+
repos: require(Module_Directory + '/repos/repo'),
28+
streams: require(Module_Directory + '/streams/stream'),
29+
posts: require(Module_Directory + '/posts/post')
30+
};
31+
var mongo_collections = Object.keys(data_collections);
32+
33+
var My_API_Cluster = new API_Cluster({
34+
module_directory: Module_Directory,
35+
version: Version,
36+
secrets: Secrets_Config,
37+
express: Express_Config,
38+
mongo: Object.assign(Mongo_Config, {
39+
collections: mongo_collections,
40+
logger: Logger
41+
}),
42+
pubnub: PubNub_Config,
43+
email: Email_Config,
44+
logger: Logger,
45+
limits: Limits,
46+
allow_config_override: true
47+
data_collections: data_collections
48+
}, Logger);
49+
50+
My_API_Cluster.start((error) => {
51+
if (error) {
52+
console.error('Failed to start: ' + error);
53+
process.exit(1);
54+
}
55+
});

api_server/bin/ci_api-help

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
#desc# brief command summary
4+
5+
dt-help $CI_API_TOP/bin

api_server/bin/ci_api-service

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
#desc# CIDER API service init script
4+
5+
function usage {
6+
echo "usage: $0 { start | stop | status } [-f] [-- server-args]" >&2
7+
echo >&2
8+
echo " -f run in foreground"
9+
exit 1
10+
}
11+
12+
[ -z "$CI_API_TOP" ] && echo "ci_api sandbox not loaded">&2 && exit 1
13+
[[ ! ( "$1" == start || "$1" == stop || "$1" == status ) ]] && usage
14+
15+
. $DT_TOP/lib/init_funcs.sh
16+
17+
action=$1
18+
run_fg=0
19+
OPTIND=2
20+
while getopts "f" arg
21+
do
22+
case $arg in
23+
f) run_fg=1;;
24+
*) usage;;
25+
esac
26+
done
27+
shift `expr $OPTIND - 1`
28+
29+
server_args=$*
30+
case "$action" in
31+
start)
32+
echo "Starting $CI_API_TOP/bin/api_server.js. Logging to $CI_API_LOG_DIRECTORY/api.log"
33+
if [ $run_fg -eq 1 ]; then
34+
$CI_API_TOP/bin/api_server.js $server_args
35+
else
36+
nohup $CI_API_TOP/bin/api_server.js $server_args >/dev/null 2>&1 </dev/null &
37+
sleep 1
38+
service_status api_server.js
39+
fi
40+
;;
41+
stop)
42+
service_stop api_server.js
43+
sleep 2
44+
service_status api_server.js
45+
;;
46+
status)
47+
service_status api_server.js
48+
;;
49+
*)
50+
usage
51+
;;
52+
esac

api_server/config/api_test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
module.exports = {
4+
api: {
5+
host: process.env.CI_API_HOST,
6+
port: process.env.CI_API_PORT
7+
},
8+
mongo: {
9+
host: process.env.CI_API_MONGO_HOST,
10+
port: process.env.CI_API_MONGO_PORT,
11+
database: process.env.CI_API_MONGO_DATABASE
12+
}
13+
};

0 commit comments

Comments
 (0)