This custom resource type allows you to send an email to your users.
The Email resource is built on the Nodemailer module for Node.js; much of the documentation on this page is taken from their README.
In your app's root directory, type npm install dpd-email
into the command line or download from source. This should create a dpd-email
directory in your app's node_modules
directory.
See Installing Modules for details.
Before using the email resource, you must go to its Dashboard page and configure it.
These settings are required:
host
: The hostname of your SMTP provider.port
: The port number of your SMTP provider. Defaults to 25; 587 is also common.ssl
: If checked, use SSL to communicate with your SMTP provider. Unneeded for port 587; as it will automatically upgrade to a secure connection.username
: The SMTP username for your app.password
: The SMTP username for your app.These settings are optional:
defaultFromAddress
: A "from" email address to provide by default. If this is not provided, you will need to provide this address in every request.internalOnly
: If checked, only allow internal requests (such as those from events) to send emails. Recommended for security.productionOnly
: If checked, attempting to send an email in the development
environment will simply print it to the Deployd console. To send an email, call dpd.email.post(options, callback)
(replacing email
with your resource name). The options
argument is an object:
from
: The email address of the sender. Required if defaultFromAddress
is not configured. All e-mail addresses can be plain (sender@server.com
) or formatted (Sender Name <sender@server.com>
)to
: Comma separated list of recipients e-mail addresses that will appear on the To: fieldcc
: Comma separated list of recipients e-mail addresses that will appear on the Cc: fieldbcc
: Comma separated list of recipients e-mail addresses that will appear on the Bcc: fieldsubject
: The subject of the e-mail.text
: The plaintext version of the messagehtml
: The HTML version of the message// On POST /users
dpd.email.post({
to: this.email,
from: "deployd-server@example.com",
subject: "MyApp registration",
text: this.username + ",\n\n" +
"Thank you for registering for MyApp!"
}, function() {});
This custom resource type allows you to write an event that will run when the resource's route receives a GET
or POST
request.
In your app's root directory, type npm install dpd-event
into the command line or download the source. This should create a dpd-event
directory in your app's node_modules
directory.
See Installing Modules for details.
The On POST
event will be executed when the resource's route (or a subroute) receives a POST
request, and likewise with the On GET
event.
It is strongly recommended that you reserve the On GET
event for operations that return a value, but don't have any side effects of modifying the database or performing some other operation.
If your resource is called /add-follower
, you can trigger its POST
event from dpd.js:
dpd.addfollower.post('320d6151a9aad8ce', {userId: '6d75e75d9bd9b8a6'}, function(result, error) {
// Do something
})
And over HTTP:
POST /add-follower/320d6151a9aad8ce
Content-Type: application/json
{
"userId": "6d75e75d9bd9b8a6"
}
In addition to the generic custom resource event API, the following functions and variables are available while scripting the Event resource:
Sets the response body. The result
argument can be a string or an object.
// On GET /top-score
dpd.scores.get({$limit: 1, $sort: {score: -1}, function(result) {
setResult(result[0]);
});
The URL of the request, without the resource's base URL. If the resource is called /add-follower
and receives a request at /add-follower/320d6151a9aad8ce
, the url
value will be /320d6151a9aad8ce
.
// On GET /statistics
// Get the top score
if (url === '/top-score') {
dpd.scores.get({$limit: 1, $sort: {score: -1}, function(result) {
setResult(result[0]);
});
}
An array of the parts of the url, separated by /
. If the resource is called /add-follower
and receives a request at /add-follower/320d6151a9aad8ce/6d75e75d9bd9b8a6
, the parts
value will be ['320d6151a9aad8ce', '6d75e75d9bd9b8a6']
.
// On POST /add-score
// Give the specified user (/add-score/:userId) 5 points
var userId = parts[0];
if (!userId) cancel("You must provide a user");
dpd.users.put({id: userId}, {score: {$inc: 5}}, function(result, err) {
if (err) cancel(err);
});
The query string object.
// On GET /sum
// Return the sum of the a and b properties (/sum?a=5&b=1)
setResult(query.a + query.b);
The body of the request.
// On POST /sum
// Return the sum of the a and b properties {a: 5, b: 1}
setResult(body.a + body.b);
This custom resource type allows you to import collections from an existing MongoDB.
Create a project. Then install the dpd-importer module.
dpd create my-app
cd my-app
mkdir node_modules
npm install dpd-importer
dpd -d
In your dashboard - click the green new resource button and choose Importer.
Give the new resource the default name "/importer". Open it by clicking "IMPOTER" in the left menu.
Enter the information of your old MongoDB server. Clicking on Start Import will start creating deployd collections from data in the provided db by streaming data directly from the old db into your new deployd db. The importer will do its best to create properties based on the types it infers from your data.
This custom resource type allows you to store and retrieve files from an Amazon S3 bucket.
In your app's root directory, type npm install s3-bucket-resource
into the command line or download the source. This should create a dpd-s3
directory in your app's node_modules
directory.
See Installing Modules for details.
Before you can use the S3 Bucket resource, you must set the three properties on its "Config" page:
bucket
: The name of your S3 Bucketkey
: The security key of your S3 Bucketsecret
: The secret key of your S3 BucketThere are two ways to upload files. Both ways require HTTP access; you cannot upload files with dpd.js.
Send a POST
request to the url where you want to upload the file, including the file name. Set the Content-Type
header to that of the file you are uploading and pass the file's content in the request body.
It will return a 200 OK
if the upload was successful. If there was an error, it will return the error directly from S3. This is usually in XML; see Amazon's S3 documentation for information.
POST /my-bucket/README.txt
Content-Type: text/plain
Hello, world!
200 OK
You can upload files directly from a browser using the multipart/form-data
type and the <input type="file" />
tag:
<form action="/installer-downloads" enctype="multipart/form-data" method="post">
<input type="file" name="upload" multiple="multiple" />
<button type="submit">Upload</button>
</form>
To send a multipart request manually, send a POST
request to the url where you want to upload the file, not including the file name. The Content-Type
header must be multipart/form-data
. Set the request body according to the multipart/form-data standard.
If the upload was successful and there is a Referrer
header on the request (e.g. if it was submitted as a form from a browser), the response will redirect to the referrer. Otherwise, it will return 200 OK
. If there was an error, it will return the error directly from S3. This is usually in XML; see Amazon's S3 documentation for information.
To download a file, send a GET
request to the url where the file exists.
GET /my-bucket/README.txt
200 OK
Content-Type: text/plain
Hello, world!
To delete a file, send a DELETE
request to the url where the file exists.
DELETE /my-bucket/README.txt
200 OK
This can also be done with dpd.js:
dpd.mybucket.del('README.txt', function(response, error) {
// Do something
});
The S3 Bucket Resource has three events:
On Upload
: Executed before a file is uploaded to S3.On Get
: Executed before a file is downloaded from S3.On Delete
: Executed before a file is deleted.The URL of the request. Does not include the resource's name; if the request URL is /my-bucket/README.txt
, the url
property will be /README.txt
.
Only available in On Upload
. The size of the file, in bytes.
// On Upload
// Set a limit on file size
if (fileSize > 1024*1024*1024) { // 1GB
cancel("File is too big; limit is 1GB");
}
Only available in On Upload
. The name of the file that is being uploaded.
// On Upload
dpd.uploads.post({ filename: fileName, creator: me.id }, function() {})
Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.
This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!