Code Monkey home page Code Monkey logo

hosting-demo's Introduction

Decoupled Frontend and Backend Hosting

This segment will help you serve an node/express application via AWS Lambda and React frontend using vercel. This tutorial will assume that you have a code editor, npm, and git on your computer. Additionally, we assume you have an AWS account set up.

File Structure

There are a lot of files in this repository which might make it confusing on what each does.

  • my-app: this folder contains the frontend React application
  • .gitignore: file that restricts some files from being pushed to git, we might want to do this to prevent sensitive information (API Keys) from being public
  • package.json: contains all the libraries and scripts that we are going to use
  • index.js: our backend application

Instructions

AWS + Serverless Setup

  1. Make sure you have an AWS account and an IAM role with the following permissions:
    • AmazonAPIGatewayAdministrator
    • AmazonS3FullAccess
    • AWSCloudFormationFullAccess
    • AWSLambda_FullAccess
    • CloudWatchLogsFullAccess
    • IAMFullAccess
  2. Go to the security credentials tab and create an access key.
  3. Install the serverless framework
    npm install -g serverless
    
  4. Configure serverless:
    $ sls config credentials \
    --provider aws \
    --key PUBLIC_KEY \
    --secret SECRET_KEY
    
  5. Install node dependencies with npm install
  6. Confirm installation with offline run sls offline start --httpPort 5000
  7. Deploy with sls deploy

Run React Code

The code has already been written so lets verify that everything is working as expected.

  1. Go to the react directory my-app
  2. Run npm run start to start the application -> your app should be running on localhost:3000
  3. If everything went well, then you should be seeing the default React app with "Testing, sending hello" on the screen.

Vercel Setup

We are going to deploy the frontend app on vercel, a common hosting platform for frontend (and now backend) applications. Also make sure that you have the repository forked.

  1. Make sure you have a vercel account by visiting this website.
  2. Add a new project and add your forked repository.
  3. Choose to deploy under my-app folder and choose create-react-app.
  4. Click Deploy

hosting-demo's People

Contributors

causality-c avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.