Config 5.5: Google Push Notification

To send Google Cloud Message, define the service in Blk:

"Google" : {
  "Api_key": string,
  "Collapse_key": string,
  "Delay_while_idle": string,
  "Time_to_live": int
}

where the parameters are described here. Then in the request where you want to send APNS, define key _gapple in the output data structure other:

"_ggoogle": {
  "To": string,
  "Title": string,
  "Content": string,
  "File": string,
  "Extra": {key: value, key: value, ...},
  key, value,
  key, value
}

Again, Content is the notification body which can be constructed from File and Extra too.

Config 5.4: Apple Push Notification

To send APNS, define the service in Blk:

"Apple" : {
  "Cert": string
  "Key": string
  "Passphrase": string
}

where the parameters are described here. Then in the request where you want to send APNS, define key _gapple in the output data structure other:

"_gapple": {
  "Device_token": string,
  "Badge": int,
  "Sound": string,
  "Content": string,
  "File": string,
  "Extra": {key: value, key: value, ...},
  key, value,
  key, value
}

Again, Content is the alert body which can constructed from File and Extra too.

Config 5.3: Sending Emails

The Blk Block

Genelet has built-in services to send email, push notification and SMS. To use them, define the following keys in Blk, with values for system and connection parameters.

  • Mail: sending emails using SMTP.
  • Apple: sending APNS.
  • Google: sending GCM.
  • Sms: sending SMS text messages.

It is important to note that the services, if enabled, run in a sequence at the end of request. It blocks each other, as well as the original web request. If your web server has a slow or unreliable connection to the service providers, you should look for non-blocking solutions such as message queue service.

Email Service

The Mail configuration is:

"Mail": {
  "Username": string (optional),
  "Password": string (optional),
  "SSL": bool (optional),
  "Address": string,
  "From": string,
  "Headers": {key:value, key:value}
}

where Address is the internet address of the SMTP host; Username and Password are the SMTP user account; and From is the generic email address of the sender belonging to this project. All the other system and connection parameters are put in Headers as key-value pairs.

Sending Email

You should send email at the end of a request, e.g. after a successful member signup. Just to add key _gmail to the output data structure other (see Developer Manual in each language):

"_gmail": {
  "To"     : string,
  "Subject": string,
  "Content": string,
  "File"   : string,
  "Extra"  : {key: value, key: value, ...},
  key, value,
  key, value
}

where To is the recipient email address, Subject the subject and Content the body. If Content is not given, Genelet will use the value of File, the template located under the same directory as HTML templates, and optionally, extra key-values Extra, to construct the message body. For any other possible extra key-value pairs required by the SMTP service, put them directly into _gmail.

Config 5.2: File Uploading

The steps to implement file uploading are

  • Define a proper directory called Uploaddir in config.json that is readable and writable by the server.
    "Uploaddir"       default: "/tmp"
  • In your web uploading form, define a uploading input field with type=file and name=xxx.
  • Receive the information of uploaded files in Controller.

You may upload multiple files at once, just to make sure they are assigned different names. For security reason, Uploaddir should not be open to online. After the upload, you can manually move the uploaded file to wherever you’d like.

 

Config 5.1: CORS

Genelet supports a weak CORS policy, that every browser with a proper Origin request header is allowed to retrieve API data even it is cross domain. We may modify it or allow you to customize the policy in future releases.

Another way to make cross domain API access is to use JSONP, see Section 2.3.

Config 4.3: Caching

The Cache case lies between Static and Reroute,

  • It will look at the static file pointed by the URL. If it exists and is validate, serve it (including a proper authentication).
  • If it is expired as indicated by the Expire parameter, the stale cache will be deleted.
  • If it is deleted, or not existing, an internal URL will be rewritten in the same way as Case=Reroute.
  • At the end of standard serving, a new cache will be written onto disk.

Because the cached page is unknown beforehand, and its status is only setup at the time of hit, we call it Schrodinger Cache, matching to the famous Schrodinger Cat experience in quantum theory.

Config 4.2: Rerouting

If Case is Reroute, Genelet will internally re-write the URL into a new URL in the standard format:

http://WEBSITE/HANDLER/role/tag/component?action=string&query…

So you need to at least map out, or by assignment, the triplet {role, tag, component} in order to rewrite meaningfully. If role is a login role, a proper authentication is automatically enforced.

Here is an example of pattern:

{
"Reg": "^\/(\w+)/(\d+)-([\w\_]+)\.(\w+)\/$"
"Mats": ["role", "book_id", "subject", "tag"]
"Case": "Reroute"
"Que": "component=book&action=edit"
}

So a GET request to

http://WEBSITE/admin/1234-New_York_Weather.html

will be re-written internally to

http://WEBSITE/HANDLER/admin/html/book?action=edit&book_id=1234&subject=New_York_Weather

 

 

 

Config 4.1: Protect Static Content

In pattern, set Case to be Static,  and assign a protected role in the pattern match or in Que.

For this case, the matched content is a permanent static file such as an image, a video or a PDF. By inspecting if there is a protected role from the match, you can enforce visitors to login before viewing it. For example, visiting to

http://WEBSITE/admin/1234.html

will be matched to the pre-defined pattern

{
"Reg": "^\/(\w+)/(\d+)\.(\w+)\/$"
"Mats": ["role", "book_id", "tag"]
"Case": "Static"
}

From the matched list of variables, we have role=admin, book_id=1234 and tag=html. Since admin is a protected role, one has to login in order to view the file.

The Static case will always look for a static file on disk, whether or not it actually exists. If not, a 404 Not Found error will be displayed.