npm install
npm lint
npm run testdata
npm start
Configuration files are located under config
dir.
See https://github.com/lorenwest/node-config/wiki/Configuration-Files
Some settings (e.g AWS credentials) must be set only as Environment variables. Check file custom-environment-variables.json for full list.
Name | Description |
---|---|
LOG_LEVEL |
The logging level for the api's |
PORT |
The port to listen |
AUTH0_CLIENT_ID |
The auth0 client id |
JWT_SECRET |
The jwt secret |
mail.SMTP_HOST |
The smtp hostname |
mail.SMTP_PORT |
The smtp port |
mail.EMAIL_FROM |
The from email address |
mail.SMTP_USERNAME |
The smtp username |
mail.SMTP_PASSWORD |
The smtp password |
AWS_ACCESS_KEY |
The AWS Access Key see http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html |
AWS_SECRET_KEY |
The AWS Secret Key |
AWS_REGION |
Your AWS access region. You should use all services from the same region (Currently only S3 is used). |
S3_BUCKET |
The S3 bucket name for file upload. |
AWS settings are optional to set, but file upload will not working (you can use other features).
mailgun is used as mail service.
Default SMTP Login
and Default Password
and set them as environment variables.
export SMTP_USERNAME=When we create an account on mailgun, by default only sandbox domain is enabled. To successfully send email from this sandbox domain you have to add the user to authorized recipients list.
test/Provider-dsp.postman_collection
, test/Provider-dsp-env.postman_environment.json
.provider1
- provder6
, password 123456
login , when login success ,the token will be injected to postman env.import test/NFZ.postman_collection.json
it contains only endpoints for No Fly Zone endpoints
I added three query parameters returnNFZ
, nfzFields
and nfzLimit
to API PUT /drones/{id}
for getting the array of violated No fly zones in the response data.
A Sample usage to get the violated no fly zones with fields description
, isActive
, isPermanent
:
curl -X PUT -H "Content-Type: application/json" -d '{
"lat":38.90709540316193,
"lng":-77.03920125961304
}' "$URL/drones/5866f36af66a5654a0816991?returnNFZ=true&nfzFields=description,isActive,isPermanent"
The response data will contain an extra field noFlyZones
, which contains an array of NoFlyZone
that the drone has violated.
You could specified the returned fields of noFlyZones
by nfzFields
parameter. If you omit the nfzFields
, all fields except the location
will be returned.
The parameter nfzLimit
is for limit the number of returned NoFlyZone
s, if it is omitted, then all the NoFlyZone
s are returned.
Note: the _id
of the NoFlyZone
is always returned.
The approach to get the array of violated no fly zones is based on the NoFlyZoneService.search
, the steps are:
{
isActive: true,
matchTime: true,
geometry: {
type: 'Point',
coordinates: drone.currentLocation,
},
projFields: ['circle', 'description', 'startTime', 'endTime', 'isActive', 'isPermanent', 'mission'],
}
NoFlyZoneService.search
to search no fly zones. Since we only needs to get part of the fields of NoFlyZone
, I added a field projFields
to the search criteria.
The field projFields
could search in MongoDB with projection, which helps to improve the performance.
Additionally, the projFields
could be overrided by nfzFields
if it is provided.
nfzFields=description,isActive,isPermanent
will be converted to ['description', 'isActive', 'isPermanent']
.items
field to the response of this API. It is added to the field noFlyZones
.
I added another three query parameters nearDronesMaxDist
, nearDroneFields
and nearDronesLimit
to API PUT /drones/{id}
for getting the nearest drones.
A Sample usage to get 100 nearest drones within 1000 meters:
curl -X PUT -H "Content-Type: application/json" -d '{
"lat":38.90709540316193,
"lng":-77.03920125961304
}' "$URL/drones/5866f36af66a5654a0816991?nearDronesMaxDist=1000&nearDronesLimit=100&nearDroneFields=currentLocation,status,name,description"
The response data will contain an extra field nearestDrones
. This field contains an array of Drones
(100 at most) that are ordered by distance.
To avoid return all fields of drones in the response data, you could specify the fields to be returned by nearDroneFields
. The example above returns the fields currentLocation
, status
, name
, description
, _id
.
If the nearDronesMaxDist
is omitted or 0, no nearest drones will be contained in the response data.
If the nearDronesLimit
is omitted or 0, only 1 nearest drone will be returned.
If the nearDroneFields
is omitted, all the fields of drones will be returned, which is not necessary. So this field is suggested to be provided.
A new field dist
is contained in the response data for indicating the distance (in meter) between the drone and the current drone.
Note: the _id
of Drone
is always returned.
The approach to get the array of nearest drones is based on the geospatial of MongoDB. The steps are:
2dsphere
index to Drone.currentLocation
, since it is not a required field, we need to specify sparse: true
.dist
field to the response data, we use $geoNear
instead of $nearSphere
.
Set the $geoNear
option as
{
near: {
type: 'Point',
coordinates: drone.currentLocation,
},
distanceField: 'dist',
maxDistance: nearDronesMaxDist,
spherical: true,
query: {
_id: { $ne: ObjectId(id) },
},
}
which means to search by Point
and filter the current drone itself.
limit
and $project
according to the query parameter nearDronesLimit
, nearDroneFields
.Drone
and add returned array to the response of this API. The array is added to the field nearestDrones
.
you also can export those values before run(data from forum).
export AUTH0_CLIENT_ID="3CGKzjS2nVSqHxHHE64RhvvKY6e0TYpK"
export JWT_SECRET="fJtXfFYt-F9iees7CSw8rOOr-tYsJocoZTz3pLF5NynamB07JFPeFOEuzfbcT7SD"
export MONGOLAB_URI="mongodb://topcoder:t0pP455@ds147777.mlab.com:47777/dsp1"
export SMTP_HOST="smtp.gmail.com"
export SMTP_PORT="465"
export SMTP_USERNAME="youremail"
export SMTP_PASSWORD="yourpassword"
export EMAIL_FROM="your@email.com"
Open S3 console https://console.aws.amazon.com/s3
Create Bucket
Check Region Name
to Code
mapping here http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html and set AWS_REGION
Select tab Properties from the top right menu
Expand Permissions tab
Click on Add bucket policy and set below policy
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::dsp-21472/*"
}
]
}
Update dsp-21472
to your bucket name.
Click on Add CORS Configuration and set below policy
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
In production mode, you should restrict `AllowedOrigin`.