-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
162 changed files
with
182,523 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,78 @@ | ||
# Compiled class file | ||
*.class | ||
.DS_Store | ||
**/.DS_Store | ||
.vscode | ||
**/.vscode | ||
|
||
# Log file | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# BlueJ files | ||
*.ctxt | ||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
*.env | ||
.env.local | ||
.env.staging | ||
|
||
|
||
# next.js build output | ||
.next | ||
|
||
.DS_STORE | ||
|
||
# Certificates and Keys | ||
labs/security/secure-tiller/*.pem | ||
labs/security/secure-tiller/*.srl | ||
× | ||
Drag and Drop | ||
The image will be downloaded by Fatkun |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
# service-tracker | ||
# service-tracker sample app | ||
|
||
|
||
### Deploy | ||
|
||
```bash | ||
|
||
kubectl apply -f ./k8s/mongodb.yaml | ||
|
||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
node_modules/ | ||
npm-debug.log | ||
.idea/ | ||
dist/ | ||
.env | ||
.env.local | ||
.env.staging |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM node:10.9.0-alpine | ||
|
||
WORKDIR /usr/src/app | ||
COPY package*.json ./ | ||
RUN npm ci | ||
|
||
COPY . . | ||
ENV NODE_ENV "development" | ||
EXPOSE 3009 | ||
|
||
CMD [ "npm", "run", "container" ] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
const bodyParser = require('body-parser'); | ||
const createError = require('http-errors'); | ||
const dayjs = require('dayjs'); | ||
const express = require('express'); | ||
const logger = require('morgan'); | ||
const mongoose = require('mongoose'); | ||
const path = require('path'); | ||
const relativeTime = require('dayjs/plugin/relativeTime'); | ||
|
||
dayjs.extend(relativeTime); | ||
|
||
global.start = dayjs().valueOf(); | ||
|
||
if (process.env.NODE_ENV != 'container') { | ||
require('dotenv').config({ path: path.join(__dirname, '.env.local') }); | ||
} | ||
|
||
const appInsights = require('applicationinsights'); | ||
|
||
appInsights | ||
.setup() | ||
.setAutoDependencyCorrelation(true) | ||
.setAutoCollectRequests(true) | ||
.setAutoCollectPerformance(true) | ||
.setAutoCollectExceptions(true) | ||
.setAutoCollectDependencies(true) | ||
.setAutoCollectConsole(true) | ||
.setUseDiskRetryCaching(true) | ||
.start(); | ||
|
||
mongoose.set('useCreateIndex', true); | ||
mongoose.set('useFindAndModify', false); | ||
|
||
require('./models/mongo/flights'); | ||
require('./models/mongo/latestFlight'); | ||
require('./models/mongo/quakes'); | ||
require('./models/mongo/latestQuake'); | ||
require('./models/mongo/weather'); | ||
require('./models/mongo/latestWeather'); | ||
|
||
mongoose.Promise = global.Promise; | ||
|
||
const app = express(); | ||
|
||
var mongoPrefix = "mongodb://" | ||
var user = process.env.MONGODB_USER | ||
var password = process.env.MONGODB_PASSWORD | ||
|
||
var cosmosConnectString = mongoPrefix.concat(user,`:`,password,`@`,user,`.documents.azure.com:10255/hackfest?ssl=true`) | ||
|
||
if (process.env.NODE_ENV != 'local') { | ||
mongoose.connect( | ||
cosmosConnectString, | ||
{ | ||
user: user, | ||
pass: password, | ||
useNewUrlParser: true | ||
} | ||
); | ||
} else { | ||
mongoose.connect( | ||
'mongodb://localhost/demo:27017', | ||
{ useNewUrlParser: true } | ||
); | ||
} | ||
|
||
const apiRouter = require('./routes/api'); | ||
|
||
var db = mongoose.connection; | ||
|
||
db.on('error', err => { | ||
appInsights.defaultClient.trackEvent({ name: 'MongoConnError' }); | ||
console.log(err); | ||
}); | ||
|
||
db.once('open', () => { | ||
appInsights.defaultClient.trackEvent({ name: 'MongoConnSuccess' }); | ||
console.log('connection success with Mongo'); | ||
}); | ||
|
||
app.set('etag', 'strong'); | ||
app.use(logger('dev')); | ||
app.use(bodyParser.json({ limit: '2mb' })); | ||
app.use('/', apiRouter); | ||
|
||
app.use(function(req, res, next) { | ||
next(createError(404)); | ||
}); | ||
|
||
app.use(function(req, res, next) { | ||
if (req.method === 'GET' || req.method === 'POST') { | ||
appInsights.defaultClient.trackNodeHttpRequest({ | ||
request: req, | ||
response: res | ||
}); | ||
} | ||
|
||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
res.setHeader( | ||
'Access-Control-Allow-Methods', | ||
'GET, POST, OPTIONS, PUT, PATCH, DELETE' | ||
); | ||
res.setHeader( | ||
'Access-Control-Allow-Headers', | ||
'X-Requested-With,content-type' | ||
); | ||
|
||
res.append('Last-Modified', new Date().toUTCString()); | ||
|
||
next(); | ||
}); | ||
|
||
// error handler | ||
app.use(function(err, req, res, next) { | ||
// set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get('env') === 'development' ? err : {}; | ||
|
||
// render the error page | ||
res.status(err.status || 500); | ||
res.send(err); | ||
}); | ||
|
||
module.exports = app; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
const app = require('../app'); | ||
const debug = require('debug')('node-data-api:server'); | ||
const http = require('http'); | ||
|
||
/** | ||
* Get port from environment and store in Express. | ||
*/ | ||
|
||
const port = normalizePort(process.env.PORT || '3009'); | ||
app.set('port', port); | ||
|
||
/** | ||
* Create HTTP server. | ||
*/ | ||
|
||
const server = http.createServer(app); | ||
|
||
/** | ||
* Listen on provided port, on all network interfaces. | ||
*/ | ||
|
||
server.listen(port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
/** | ||
* Normalize a port into a number, string, or false. | ||
*/ | ||
|
||
function normalizePort(val) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "error" event. | ||
*/ | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "listening" event. | ||
*/ | ||
|
||
function onListening() { | ||
var addr = server.address(); | ||
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; | ||
debug('Listening on ' + bind); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* JSON Response for Express Web API's | ||
* @param {object} res - Express Response Object | ||
* @param {any} msg - Response message as property in object | ||
* @param {number} status - HTTP Status code | ||
* @param {object} payload - JSON payload object | ||
*/ | ||
|
||
module.exports.json = (res, msg, status, payload) => { | ||
|
||
res.json( { message: msg, payload: payload } ).status( status ) | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
var Schema = mongoose.Schema; | ||
|
||
var flightSchema = new Schema({ | ||
Timestamp: String, | ||
FeatureCollection: mongoose.Schema.Types.Mixed | ||
}); | ||
|
||
mongoose.model('Flights', flightSchema, 'Flights'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
var Schema = mongoose.Schema; | ||
|
||
var latestSchema = new Schema({ | ||
Timestamp: String, | ||
Created: { type: Date, default: Date.now } | ||
}); | ||
|
||
mongoose.model('LatestFlight', latestSchema, 'LatestFlight'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const latestSchema = new Schema({ | ||
Timestamp: String, | ||
Created: { type: Date, default: Date.now } | ||
}); | ||
|
||
mongoose.model('LatestQuake', latestSchema, 'LatestQuake'); |
Oops, something went wrong.