Skip to content

Instantly share code, notes, and snippets.

@timgshi
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save timgshi/0b3d8adc947c29d7336b to your computer and use it in GitHub Desktop.

Select an option

Save timgshi/0b3d8adc947c29d7336b to your computer and use it in GitHub Desktop.
Files to host a template app download page for DryDock.
// These two lines are required to initialize Express in Cloud Code.
var express = require('express');
var app = express();
var versionTracker = require('cloud/versionTracker.js');
var VDDModelApp = Parse.Object.extend("VDDModelApp");
// Global app configuration section
app.set('views', 'cloud/views'); // Specify the folder to find templates
app.set('view engine', 'ejs'); // Set the template engine
app.use(express.bodyParser()); // Middleware for reading request body
app.post('/builds', function(req, res) {
console.log(JSON.stringify(req.body));
return res.send("");
});
app.get('/appdownload', function(req, res) {
return res.render('appdownloadERROR');
});
app.get('/appdownload/:objectId', function(req, res) {
var modelAppQuery = new Parse.Query(VDDModelApp);
modelAppQuery.get(req.params.objectId).then(function(modelApp) {
if (!modelApp) {
return res.render('appdownloadERROR');
} else {
var renderPackage = {};
renderPackage['name'] = modelApp.get('name');
renderPackage['version_number'] = modelApp.get('version_number');
renderPackage['install_url'] = modelApp.get('install_url');
if (modelApp.get('image')) {
renderPackage['icon_url'] = modelApp.get('image').url();
} else {
renderPackage['icon_url'] = "http://files.parsetfss.com/8ea13206-bb1e-43a9-9351-a410a901ac61/tfss-cd12e48a-3526-4884-af28-c16986314992-DryDock_Icon120x120.png";
}
renderPackage['description'] = modelApp.get('description');
return res.render('appdownload', renderPackage);
}
});
});
app.listen();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DryDock</title>
<!-- Sets initial viewport load and disables zooming -->
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<!-- Makes your prototype chrome-less once bookmarked to your phone's home screen -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!-- Include the compiled Ratchet CSS -->
<link href="/ratchet/css/ratchet.min.css" rel="stylesheet">
<!-- Include the compiled Ratchet JS -->
<script src="/ratchet/js/ratchet.min.js"></script>
</head>
<body>
<!-- Make sure all your bars are the first things in your <body> -->
<header class="bar bar-nav">
<h1 class="title"><%= name %></h1>
</header>
<!-- Wrap all non-bar HTML in the .content div (this is actually what scrolls) -->
<div class="content">
<ul class="table-view">
<li class="table-view-cell media">
<a class="navigate-right" href="<%= install_url %>">
<img class="media-object pull-left" src="<%= icon_url %>">
<div class="media-body">
<%= name %>
<p>
<em><%= version_number %></em>
</p>
<p>
<%= description %>
</p>
</div>
</a>
</li>
</ul>
<p class="content-padded">Thanks for downloading <%= name %>! Click above to install the app.</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DryDock</title>
<!-- Sets initial viewport load and disables zooming -->
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<!-- Makes your prototype chrome-less once bookmarked to your phone's home screen -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!-- Include the compiled Ratchet CSS -->
<link href="/ratchet/css/ratchet.min.css" rel="stylesheet">
<!-- Include the compiled Ratchet JS -->
<script src="/ratchet/js/ratchet.min.js"></script>
</head>
<body>
<!-- Make sure all your bars are the first things in your <body> -->
<header class="bar bar-nav">
<h1 class="title">DryDock</h1>
</header>
<!-- Wrap all non-bar HTML in the .content div (this is actually what scrolls) -->
<div class="content">
<h3 class="content-padded">Oh no! We couldn't find that app. Sorry :/.</h2>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment