-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from sdl60660/global
Global Paths
- Loading branch information
Showing
52 changed files
with
4,236 additions
and
2,702,554 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
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 @@ | ||
web: npm start --prefix name_server |
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
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,42 @@ | ||
import json | ||
|
||
with open('data/ne_10m_geography_marine_polys.geojson', 'r') as f: | ||
seas = json.load(f)['features'] | ||
|
||
with open('data/ne_10m_lakes.geojson', 'r') as f: | ||
lakes = json.load(f)['features'] | ||
|
||
|
||
output_cols = ['name','featurecla'] | ||
ocean_feature_types = ['strait', 'gulf', 'river', 'inlet', 'sound', 'lagoon', 'ocean', 'sea', 'bay', 'fjord', 'generic', 'channel', 'reef'] | ||
lake_feature_types = ['alkaline lake', 'lake', 'reservoir'] | ||
|
||
all_output_features = [] | ||
|
||
for feature in (seas + lakes): | ||
if feature['properties']['featurecla'].lower() in ocean_feature_types: | ||
stop_feature_type = 'ocean' | ||
else: | ||
stop_feature_type = 'inland lake' | ||
|
||
slimmed_feature_properties = { | ||
'stop_feature_type': stop_feature_type, | ||
'stop_feature_type_specific': feature['properties']['featurecla'].lower(), | ||
'stop_feature_name': feature['properties']['name'], | ||
} | ||
|
||
geometry = feature['geometry'] | ||
if type(geometry['coordinates'][0][0][0]) == list: | ||
geometry['type'] = "MultiPolygon" | ||
|
||
output_feature = { | ||
"type": "Feature", | ||
"geometry": geometry, | ||
"properties": slimmed_feature_properties | ||
} | ||
all_output_features.append(output_feature) | ||
|
||
# Output as a GeoJSON file for now, but then use mapshaper.org to compress to a TopoJSON | ||
output_data = {"type": "FeatureCollection", "features": all_output_features} | ||
with open('data/global_stopping_features.geojson', 'w') as f: | ||
json.dump(output_data, f) |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
307 changes: 307 additions & 0 deletions
307
data_processing/data/ne_10m_geography_marine_polys.geojson
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,5 @@ | ||
# Port number | ||
PORT=3000 | ||
|
||
# URL of the Mongo DB | ||
MONGODB_URL=mongodb://127.0.0.1:27017/node-boilerplate |
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,15 @@ | ||
{ | ||
"apps": [ | ||
{ | ||
"name": "app", | ||
"script": "src/index.js", | ||
"instances": 1, | ||
"autorestart": true, | ||
"watch": false, | ||
"time": true, | ||
"env": { | ||
"NODE_ENV": "production" | ||
} | ||
} | ||
] | ||
} |
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,43 @@ | ||
{ | ||
"name": "name_server", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "node/express name server for processing name suggestions from river runner app", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "pm2 start ecosystem.config.json --no-daemon", | ||
"dev": "cross-env NODE_ENV=development nodemon src/index.js" | ||
}, | ||
"author": "Sam Learner", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sdl60660/river-runner" | ||
}, | ||
"license": "ISC", | ||
"dependencies": { | ||
"compression": "^1.7.4", | ||
"cors": "^2.8.5", | ||
"cross-env": "^7.0.0", | ||
"dotenv": "^10.0.0", | ||
"express": "^4.17.2", | ||
"express-mongo-sanitize": "^2.1.0", | ||
"express-rate-limit": "^5.5.1", | ||
"helmet": "^4.1.0", | ||
"http-status": "^1.5.0", | ||
"joi": "^17.5.0", | ||
"mongoose": "^5.13.13", | ||
"nodemailer": "^6.3.1", | ||
"passport": "^0.5.2", | ||
"pm2": "^5.1.2", | ||
"validator": "^13.0.0", | ||
"winston": "^3.3.3", | ||
"xss-clean": "^0.1.1" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^2.0.15" | ||
}, | ||
"engines": { | ||
"node": "14.x" | ||
} | ||
} |
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,49 @@ | ||
const express = require('express'); | ||
const helmet = require('helmet'); | ||
const xss = require('xss-clean'); | ||
const mongoSanitize = require('express-mongo-sanitize'); | ||
const compression = require('compression'); | ||
const cors = require('cors'); | ||
const httpStatus = require('http-status'); | ||
const { errorConverter, errorHandler } = require('./middlewares/error'); | ||
const ApiError = require('./utils/ApiError'); | ||
|
||
const { router } = require('./routes'); | ||
|
||
const app = express(); | ||
|
||
// set security HTTP headers | ||
app.use(helmet()); | ||
|
||
// parse json request body | ||
app.use(express.json()); | ||
|
||
// parse urlencoded request body | ||
app.use(express.urlencoded({ extended: true })); | ||
|
||
// sanitize request data | ||
app.use(xss()); | ||
app.use(mongoSanitize()); | ||
|
||
// gzip compression | ||
app.use(compression()); | ||
|
||
// enable cors | ||
app.use(cors()); | ||
app.options('*', cors()); | ||
|
||
// API Routes | ||
app.use('/api', router); | ||
|
||
// send back a 404 error for any unknown api request | ||
app.use((req, res, next) => { | ||
next(new ApiError(httpStatus.NOT_FOUND, 'Not Found')); | ||
}); | ||
|
||
// convert error to ApiError, if needed | ||
app.use(errorConverter); | ||
|
||
// handle error | ||
app.use(errorHandler); | ||
|
||
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,34 @@ | ||
const dotenv = require('dotenv'); | ||
const path = require('path'); | ||
const Joi = require('joi'); | ||
|
||
if (process.env.NODE_ENV !== "production") { | ||
dotenv.config({ path: path.join(__dirname, '../../.env') }); | ||
} | ||
|
||
const envVarsSchema = Joi.object() | ||
.keys({ | ||
NODE_ENV: Joi.string().valid('production', 'development', 'test').required(), | ||
PORT: Joi.number().default(3000), | ||
MONGODB_URL: Joi.string().required().description('Mongo DB url') | ||
}) | ||
.unknown(); | ||
|
||
const { value: envVars, error } = envVarsSchema.prefs({ errors: { label: 'key' } }).validate(process.env); | ||
|
||
if (error) { | ||
throw new Error(`Config validation error: ${error.message}`); | ||
} | ||
|
||
module.exports = { | ||
env: envVars.NODE_ENV, | ||
port: envVars.PORT, | ||
mongoose: { | ||
url: envVars.MONGODB_URL, | ||
options: { | ||
useCreateIndex: true, | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}, | ||
} | ||
}; |
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,26 @@ | ||
const winston = require('winston'); | ||
const config = require('./config'); | ||
|
||
const enumerateErrorFormat = winston.format((info) => { | ||
if (info instanceof Error) { | ||
Object.assign(info, { message: info.stack }); | ||
} | ||
return info; | ||
}); | ||
|
||
const logger = winston.createLogger({ | ||
level: config.env === 'development' ? 'debug' : 'info', | ||
format: winston.format.combine( | ||
enumerateErrorFormat(), | ||
config.env === 'development' ? winston.format.colorize() : winston.format.uncolorize(), | ||
winston.format.splat(), | ||
winston.format.printf(({ level, message }) => `${level}: ${message}`) | ||
), | ||
transports: [ | ||
new winston.transports.Console({ | ||
stderrLevels: ['error'], | ||
}), | ||
], | ||
}); | ||
|
||
module.exports = logger; |
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,38 @@ | ||
const mongoose = require('mongoose'); | ||
const app = require('./app'); | ||
const config = require('./config/config'); | ||
const logger = require('./config/logger'); | ||
|
||
let server; | ||
mongoose.connect(config.mongoose.url, config.mongoose.options).then(() => { | ||
logger.info('Connected to MongoDB'); | ||
server = app.listen(config.port, () => { | ||
logger.info(`Listening to port ${config.port}`); | ||
}); | ||
}); | ||
|
||
const exitHandler = () => { | ||
if (server) { | ||
server.close(() => { | ||
logger.info('Server closed'); | ||
process.exit(1); | ||
}); | ||
} else { | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
const unexpectedErrorHandler = (error) => { | ||
logger.error(error); | ||
exitHandler(); | ||
}; | ||
|
||
process.on('uncaughtException', unexpectedErrorHandler); | ||
process.on('unhandledRejection', unexpectedErrorHandler); | ||
|
||
process.on('SIGTERM', () => { | ||
logger.info('SIGTERM received'); | ||
if (server) { | ||
server.close(); | ||
} | ||
}); |
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,39 @@ | ||
const mongoose = require('mongoose'); | ||
const httpStatus = require('http-status'); | ||
const config = require('../config/config'); | ||
const ApiError = require('../utils/ApiError'); | ||
|
||
const errorConverter = (err, req, res, next) => { | ||
let error = err; | ||
if (!(error instanceof ApiError)) { | ||
const statusCode = | ||
error.statusCode || error instanceof mongoose.Error ? httpStatus.BAD_REQUEST : httpStatus.INTERNAL_SERVER_ERROR; | ||
const message = error.message || httpStatus[statusCode]; | ||
error = new ApiError(statusCode, message, false, err.stack); | ||
} | ||
next(error); | ||
}; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const errorHandler = (err, req, res, next) => { | ||
let { statusCode, message } = err; | ||
if (config.env === 'production' && !err.isOperational) { | ||
statusCode = httpStatus.INTERNAL_SERVER_ERROR; | ||
message = httpStatus[httpStatus.INTERNAL_SERVER_ERROR]; | ||
} | ||
|
||
res.locals.errorMessage = err.message; | ||
|
||
const response = { | ||
code: statusCode, | ||
message, | ||
...(config.env === 'development' && { stack: err.stack }), | ||
}; | ||
|
||
res.status(statusCode).send(response); | ||
}; | ||
|
||
module.exports = { | ||
errorConverter, | ||
errorHandler, | ||
}; |
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 @@ | ||
const rateLimit = require('express-rate-limit'); | ||
|
||
const authLimiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, | ||
max: 20, | ||
skipSuccessfulRequests: true, | ||
}); | ||
|
||
module.exports = { | ||
authLimiter, | ||
}; |
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,24 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const querySchema = new mongoose.Schema({ | ||
lat: { | ||
type: String, | ||
required: true, | ||
}, | ||
lng: { | ||
type: String, | ||
required: true, | ||
}, | ||
from_share_link: { | ||
type: Boolean, | ||
required: true, | ||
}, | ||
query_error: { | ||
type: Boolean, | ||
required: false | ||
}, | ||
timestamp: Number, | ||
}); | ||
|
||
const Query = mongoose.model("Query", querySchema); | ||
module.exports = Query; |
Oops, something went wrong.