• This repository has been archived on 12/Feb/2022
  • Stars
    star
    115
  • Rank 295,242 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Heroku template mobile app Quiz Live

This sample application implements a simple "live quiz" mobile game. The mobile app itself is a hybrid AngularJS app composed of HTML, CSS and Javascript. The server side is implemented as an Express Node.js application running on top of a Postgres database.

This application should serve as a good base for creating mobile apps to deploy on Heroku.

Deploy

How to play

A set of players opens the app on their phones and registers to play. The app maintains this list of users plus a set of quiz questions. During the game, questions are presented to each user running the app, and points are awarded for correct answers to questions. As players earn points a realtime leaderboard is displayed to each player.

Notification of new questions and answer results are broadcast via Websocket to the mobile app using the SocketIO library.

Game screenshot

Admin screenshot

Architecture

The app has two major pieces: An AngularJS based client app which comprises the front-end which runs on the phone, and a Node.js backend which provides an API to the client app for user registration, data storage, and event broadcast.

/---mobile app-----\
| Ionic framework  |
| Angular JS       |
\------------------/
       |
       | http / websocket
       |
/-------Node.js app-\
|                   |
| express           |
|   bookshelf       |
|      node-pg      |
\-------------------/
       |
   [Postgres DB]

Deployment

The app can be deployed to Heroku, and distributed to the mobile device either through the mobile web browser, or by compiling the AngularJS application into a native app using an Apache Cordova container.

Installation and setup

Clone this repo to your local machine and install the requirements:

npm install

Now create a database on your local server called quizlive:

createdb quizlive

Now create the database schema and initial data:

./bootstrap.sh

And now run the server app:

node server.js

and open the client app:

http://localhost:5000

From the home screen click "Register". Enter your name and email and click Register. The first user is automatically marked as the administrator. Click the Open Admin Page link on the quiz page.

On the admin page, use the following controls

Next Question - queue up the next quiz question Restart Quiz - erase all current scores and start over

As you click Next Question a new question will appear automatically for anyone running the app. Additional users can register for the app and play at the same time. Users accumulate points by answering questions correctly, with a bonus awarded to the person who answers correctly first.

Deploy to Heroku

When you are ready to share the app, just create a new Heroku app, provision a Postgres database addon for your app, and then deploy the code. After you deploy you should bootstrap the database:

$ heroku run ./bootstrap.sh

Understanding the code

The components of the application are organized as follows:

component folder
client app client
..app code client/js
..html templates client/templates
..ionic/angular frameworks client/lib
express app server.js, server/*
..db migrations server/migrations
..question list server/load_question.js
admin app admin

Front-end app

The front-end app is an AngularJS single page application. Thus all the HTML and Javascripted are loaded and run in a single WebView control on the phone. Different screens and navigation are all drawn in the browser DOM.

Angular

Accessing Force.com

As an option, the app can be configured so that each person who registers to play is recorded as a Lead record in Salesforce. This template shows how to access the Force.com API to exchange data with a Salesforce account. See FORCE_README for full instructions.

Debugging

Install node-debug to use the Chrome debugger with Node.js:

$ npm install node-debug

And to use, just run with node-debugger. After the Chrome debugger opens, make sure to click Run so the server starts:

$ node-debug server.js

Building a native app

To bundle your client app as a native mobile app, you can use the Cordova tool. Note that to build a native app you will need the corresponding native build tools. So for iOS apps you will need Xcode installed, and for Android apps you will need to have the Android SDK installed.

Install Cordova:

$ sudo npm install -g cordova

Install an application simulator:

$ sudo npm install -g ios-sim

Initialize the wrapper:

$ mkdir wrapper
$ cd wrapper
$ cordova create . QuizLive
$ rm -rf www
$ ln -s ../client www

Now add one or more platform targets:

$ cordova platform add ios
$ cordova platform add android

Now build the native app:

$ cordova compile ios

And run in the emulator:

$ cordova run --emulator

Fixing AJAX calls

The Ajax calls used in the Angular client are written using simple relative paths. This means that they automatically use the host value inferred from the domain which served the client JS files. This all works properly when the client app is served from a web server.

However, when you package the client files into the Cordova wrapper, then they are provided to the mobile device from the local filesystem, rather than being served from the web. As a result there is no domain to tell the Ajax calls where to go. To correct this, you need to specify your web domain explicitly in all client Ajax calls, such as the login call:

https://github.com/heroku/mobile-template1/blob/master/client/js/services.js#L80

Contact

Scott Persinger [email protected]

License

See LICENSE. This code is available under the MIT license.

More Repositories

1

react-refetch

A simple, declarative, and composable way to fetch data for React components
JavaScript
3,439
star
2

legacy-cli

Heroku CLI
Ruby
1,370
star
3

heroku-pg-extras

A heroku plugin for awesome pg:* commands that are also great and fun and super.
JavaScript
1,306
star
4

heroku-buildpack-nodejs

The official Heroku buildpack for Node.js apps.
Shell
1,265
star
5

node-js-getting-started

Getting Started with Node on Heroku
EJS
1,054
star
6

logplex

[DEPRECATED] Heroku log router
Erlang
984
star
7

heroku-buildpack-python

The official Heroku buildpack for Python apps
Ruby
953
star
8

heroku-django-template

A Django 2.0 base template featuring all recommended best practices for deployment on Heroku and local development.
Python
901
star
9

node-js-sample

This repository is deprecated. Head over to https://github.com/heroku/node-js-getting-started
JavaScript
847
star
10

cli

Heroku CLI
JavaScript
847
star
11

rails_12factor

Ruby
845
star
12

python-getting-started

Getting Started with Python on Heroku.
Python
818
star
13

heroku-buildpack-php

The official PHP buildpack for Heroku.
Shell
799
star
14

heroku-buildpack-go

Heroku Go Buildpack
Shell
790
star
15

heroku-buildpack-ruby

Heroku's Ruby Buildpack
Ruby
778
star
16

hk

DEPRECATED: see
Go
709
star
17

heroku-buildpack-static

[DEPRECATED] Heroku buildpack for handling static sites and single page web apps
Ruby
681
star
18

heroku-repo

Plugin for heroku CLI that can manipulate the repo
JavaScript
680
star
19

vegur

Vegur: HTTP Proxy Library
Erlang
620
star
20

heroku-accounts

Helps use multiple accounts on Heroku.
JavaScript
548
star
21

django-heroku

[DEPRECATED] Do not use! See https://github.com/heroku/django-heroku/issues/56
Python
465
star
22

heroku-buildpack-pgbouncer

Run pgbouncer in a dyno along with your application
Shell
335
star
23

devcenter-embedded-tomcat

Java
330
star
24

webapp-runner

Lightweight Application Launcher. Launch your webapp in the most popular open source web container available with a single command.
Java
319
star
25

docker-registry-client

A Go API client for the v2 Docker Registry API
Go
287
star
26

heroku-buildpack-google-chrome

Run (headless) Google Chrome on Heroku
Shell
283
star
27

stack-images

Recipies for building Heroku's stack images
Shell
264
star
28

java-getting-started

Getting Started with Java on Heroku
HTML
248
star
29

identity

[DEPRECATED] Login and OAuth management service for Heroku
CSS
247
star
30

go-getting-started

Getting Started with Go on Heroku https://devcenter.heroku.com/articles/getting-started-with-go
Dockerfile
246
star
31

heroku-buildpack-nginx

Run NGINX in a Heroku app
Shell
242
star
32

heroku-buildpack-apt

Buildpack that installs APT based dependencies
Shell
239
star
33

log-shuttle

HTTP log transport.
Go
236
star
34

terrier

Terrier is a Image and Container analysis tool that can be used to scan Images and Containers to identify and verify the presence of specific files according to their hashes.
Go
226
star
35

umpire

HTTP metrics monitoring endpoint
Ruby
221
star
36

platform-api

Ruby HTTP client for the Heroku API
Ruby
211
star
37

starboard

onboarding, offboarding, or crossboarding made easy
SCSS
204
star
38

salesforce-bulk

Python interface to the Salesforce.com Bulk API
Python
203
star
39

php-getting-started

Getting Started with PHP on Heroku
Twig
200
star
40

heroku-container-tools

DEPRECATED Heroku Toolbelt plugin to help configure, test and release apps to Heroku using local containers.
JavaScript
195
star
41

heroku-buildpack-scala

Heroku buildpack: Scala
Shell
190
star
42

node-heroku-client

A wrapper around the Heroku API for Node.js
JavaScript
188
star
43

roadmap

This is the public roadmap for Salesforce Heroku services.
187
star
44

vulcan

A build server in the cloud.
Ruby
172
star
45

pg_lock

Use Postgres advisory lock to isolate code execution across machines
Ruby
168
star
46

awsdetailedbilling

A toolkit for importing AWS detailed billing reports into Redshift
JavaScript
167
star
47

heroku-buildpack-java

A Heroku buildpack for Java apps.
Shell
167
star
48

pulse

DEPRECATED: Real-time Heroku operations dashboard
Clojure
161
star
49

heroku.rb

DEPRECATED! Official Heroku Ruby Legacy API wrapper
Ruby
161
star
50

heroku-buildpack-multi

[DEPRECATED] Please use https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app instead
Shell
157
star
51

erlang-in-anger

A little guide about how to be the Erlang medic in a time of war. It is first and foremost a collection of tips and tricks to help understand where failures come from, and a dictionary of different code snippets and practices that helped developers debug production systems that were built in Erlang.
TeX
157
star
52

plexy

A toolkit for building excellent APIs with Elixir
Elixir
154
star
53

heroku-buildpack-multi-procfile

Everyone gets a Procfile!
Shell
150
star
54

log2viz

DEFUNCT: Realtime analysis of your Heroku app logs.
Ruby
145
star
55

heroku.py

DEPRECATED! Heroku API wrapper for Python.
Python
142
star
56

facebook-template-nodejs

JavaScript
136
star
57

ruby-getting-started

Getting Started with Ruby on Heroku
Ruby
120
star
58

heroku-buildpack-chromedriver

Installs chromedriver in a Heroku slug
Shell
117
star
59

heroku-buildpack-clojure

Heroku's buildpack for Clojure applications.
Shell
115
star
60

instruments

Collecting metrics over discrete time intervals
Go
112
star
61

heroku-sbt-plugin

An sbt plugin for deploying Heroku Scala applications
Scala
111
star
62

heroku-buildpack-erlang

Erlang buildpack
Shell
107
star
63

cli-engine

TypeScript
97
star
64

semver.io

*DEPRECATED* The semver.io instance has now been sunset: https://github.com/heroku/semver.io/issues/74
CoffeeScript
96
star
65

facebook-template-php

example facebook app for heroku
PHP
96
star
66

terraform-provider-heroku

Terraform Heroku provider
Go
95
star
67

dotnet-buildpack

ASP.NET 5 Buildpack
Shell
92
star
68

kensa

A tool to help Heroku add-on providers integrate their services with Heroku
Ruby
92
star
69

netrc

Reads and writes netrc files.
Ruby
89
star
70

hstore_example

Ruby
89
star
71

alpinehelloworld

An Alpine-based Docker example
Python
85
star
72

heroku-kong

🐒 Kong API gateway as a Heroku app
Lua
84
star
73

heroku-buildpack-hello

Shell
82
star
74

heroku-releases-retry

CLI plugin to allow retrying the latest release-phase command
JavaScript
79
star
75

faceplate

A Node.js wrapper for Facebook authentication and API
JavaScript
76
star
76

rails_stdout_logging

Logs to stdout so you don't have to
Ruby
76
star
77

shaas

Shell as a Service: API to inspect and execute scripts in a server's environment via HTTP and WebSockets
Go
75
star
78

devcenter-spring-mvc-hibernate

AspectJ
75
star
79

heroku-buildpack-core-data

A Heroku Buildpack that generates a REST webservice from a Core Data model
Shell
74
star
80

heroku-buildpack-emberjs

**This buildpack is deprecated!** Please use the official Node.js buildpack combined with the static or nginx buildpack instead.
Ruby
72
star
81

facebook-template-python

Python
69
star
82

devcenter-java

Java
62
star
83

heroku-buildpack-c

C Language Pack
Shell
62
star
84

nibs

JavaScript
61
star
85

heroku-buildpack-gradle

This is a Heroku buildpack for Gradle apps. It uses Gradle to build your application and OpenJDK to run it.
Shell
61
star
86

heroku-buildpack-ember-cli

A Heroku buildpack for ember-cli apps; powers dashboard.heroku.com
Shell
60
star
87

heroku-guardian

Easy to use CLI security checks for the Heroku platform. Validate baseline security configurations for your own Heroku deployments.
Python
59
star
88

list-of-ingredients

An example of using Create React App with Rails 5 API and ActiveAdmin on Heroku
Ruby
56
star
89

heroku-fork

Heroku CLI plugin to fork an existing app into a new app
JavaScript
55
star
90

salesforce-buildpack

Heroku Buildpack for Salesforce
Shell
53
star
91

ruby-rails-sample

Ruby
52
star
92

facebook-template-ruby

CSS
52
star
93

heroku-jupyterlab

An example of running JupyterLab on Heroku, with Amazon S3.
Python
52
star
94

heroku-maven-plugin

This plugin is used to deploy Java applications directly to Heroku without pushing to a Git repository.
Java
51
star
95

cnb-builder-images

Recipes for building Heroku's Cloud Native Buildpacks builder images
Shell
51
star
96

stillir

Cache environment variables as Erlang app variables
Erlang
51
star
97

heroku-gradle-plugin

A Gradle plugin for deploying JAR and WAR files to Heroku.
Java
49
star
98

rails_serve_static_assets

Ruby
49
star
99

x

A set of packages for reuse within Heroku Go applications
Go
49
star
100

template-java-spring-hibernate

Java
48
star