Arpith Siromoney 💬

A Double Page App

So far we’ve seen how to use a webpage to sign into an app and how we can use Universal Links to skip the step of opening the webpage — and open the app directly from the sign in email. It makes sense to support both methods of signing in, so today we’ll use koa-static to serve both the JSON file as well as the HTML file that contains the link to open the app.

Our code now looks like:

var serve = require(‘koa-static’);
var koa = require(‘koa’);
var app = koa(); 
var port = process.env.PORT || 3000; 
app.use(serve(‘public’));
app.listen(port);

The first thing you might notice is that it’s a bit shorter than it was yesterday, and that’s partly because we’ve moved the JSON into a separate file in our public directory. This is also where the HTML file is. All that needs to be done is to modify our package.json file to look like:

{ 
  "name": "constellational-web",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "koa": "*",
    "koa-static": "*"
  }
}

This tells Heroku to install the two packages we used in our code. Click on “Deploy Branch” at the bottom of your app’s deployment page on Heroku and you’re done. Your website now serves a page that lets you open the app (https://constellational.com) and it also serves an Apple App Site Association file (https://constellational.com/apple-app-site-association).

Bonus: If you “Enable Automatic Deploys”, Heroku will re-deploy your app when you make changes to files on GitHub, which I find useful.