tl;dr: Voting App allows users to create polls that everyone can vote on.
- As an authenticated user, I can keep my polls and come back later to access them.
- As an authenticated user, I can share my polls with my friends.
- As an authenticated user, I can see the aggregate results of my polls.
- As an authenticated user, I can delete polls that I decide I don't want anymore.
- As an authenticated user, I can create a poll with any number of possible items.
- As an unauthenticated or authenticated user, I can see and vote on everyone's polls.
- As an unauthenticated or authenticated user, I can see the results of polls in chart form. (This could be implemented using Chart.js or Google Charts.)
- As an authenticated user, if I don't like the options on a poll, I can create a new option.
- The server is built on Express framework and is deployed to AWS Elastic Beanstalk to ensure scalability. It interfaces with MongoDB and exposes API that the client consumes. Additionally, we use Passport.js library to implement JWT-based authentication.
- The client on the other hand is developed with React+Redux using
create-react-app
boilerplate from Facebook. It is deployed statistically to AWS S3 and CloudFront. As static files has fewer moving parts, this method of deployment requires less maintenance and is thus cheaper.
Server: npm install && npm run dev
Client: npm install && npm start
Read: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs_express.html
- Install EB CLI
brew install awsebcli
- Create a repository on AWS:
eb init --platform node.js --region us-west-2
- Create an environment on EB:
eb create <APP_NAME>
- Create a file called
.ebextensions/nodecommand.config
to tell Elastic Beanstalk what command to run to deploy:
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
- Create a file called
.ebextensions/env.config
and transfer environment variables from.env
to this file:
option_settings:
aws:elasticbeanstalk:application:environment:
NODE_ENV: "production"
MONGO_URI: "mongodb://..."
JWT_SECRET: "yourJwtSecret"
- You have to stage
.ebextensions
folder but don't commit because you don't want it to be accidentally pushed to a public repository. - Deploy the code:
eb deploy --staged
- View your app:
eb open
- Unstage the
.ebextentions
folder
- Rename
.env.example
to.env
and editREACT_APP_SERVER_URL
to your own server URL. - Run
npm run build
- The static files are generated to
build/
Using AWS Console
- Create a S3 Bucket. In the Properties, click on Static Website Hosting tab, and choose Enable website hosting. Use index.html for the Index Document. Also, use index.html for Error Document to allow react-router library to handle routes outside root.
- Next, on the Permissions tab, select Edit bucket policy. Generate a bucket policy. Fill your bucket name under "Resource." Your bucket name is given to you in the format:
arn:aws:s3:::bucket_name/*
- Upload the content of your
build/
directory
Using Command Line
- Install awscli
- Create your security credentials. You will be given AWS Access Key ID and AWS Secret Access Key. Download and store it somewhere safe.
- Run
aws configure
and enter AWS Access Key ID and AWS Secret Access Key you received from previous step. - Create a bucket by running
aws s3 mb s3://bucket-name
- Run
npm run build
if you haven't - Deploy by running
aws s3 sync build/ s3://bucket-name
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
TODO:
Add token when requesting to create or delete polls- Loading animation during fetch
Known issues:
- ~~Create Poll requests works on localhost but not when deployed to S3 ~~
Author: Kuriakin Zeng