Skip to content

ladjs/lad

Repository files navigation

lad

chat build status code coverage code style styled with prettier made with lass license

Lad is the bestNode.jsframework. Made by a formerExpressTC andKoateam member.
A lad that fell in love with alass • Built by@niftylettuce andcontributors

Project Spotlight: Forward Email @https://forwardemail.net(made with Lad)

Live Framework Demo:https://lad.sh


❤️ Love this project? Support@niftylettuce'sFOSSonPatreonorPayPal🦄

Table of Contents

Features

Lad boasts dozens of features and is extremely configurable.

Microservices

These microservices are preconfigured for security, performance, and graceful reloading.

Front-end

Back-end

  • Redis, sessions, and flash toast and modalSweetAlert2messages (usesiorediswhich has support forCluster,Sentinel,and more)
  • Koa-based webapp and API servers (uses HTTP/2 for production!)
  • Pagination built-in (usingctx-paginate)
  • RESTful API with BasicAuth and versioning
  • Automated job scheduler with cron and human-readable syntax (backed byMongooseandBree)
  • Passport-based authentication and group-based (Unix-like) permissioning
  • Stripe-inspired error handling
  • Mongoose and MongoDB with common database plugins
  • Email template engine withNodemailerand local rendering
  • Proxy eliminates need for Nginx reverse-proxy or Apache virtual hosts
  • Multilingual through built-in i18n translation support (see configuration)
  • Automatic phrase translation with Google Translate
  • Sitemap generator for simple SEO

Translation

Finally a framework that solves i18n everywhere; complete with automatic translation.

  • Translation constants built-in so youdon't repeat yourself
  • Webapp error messages and templates are translated
  • Emails are translated
  • API responses are translated
  • Database errors are translated
  • Authentication errors are translated

Email Engine

Our beautiful email engine usesemail-templates(which is also made by the creator of Lad)!

Error Handling

We've spent a lot of time designing a beautiful error handler.

Seekoa-better-error-handlerfor a complete reference.

Performance

  • Compression and zero-bloat approach
  • Stream-based file uploading
  • Graceful reloading, shutdown, and reconnection handling
  • Manifest asset revisioning
  • Amazon S3 and CloudFront ready

Security

  • Database security plugins and helpers
  • Automated tests and code coverage
  • CORS, SameSite set to "lax" (an alternative to CSRF), CSRF (sincenot all browserssupport SameSite yet) XSS, and rate limited protection
  • Dotenv support for environment-based configurations
  • App, user, and request-based logging
  • SSL-ready (seeinstructions below)

Get Started

We strictly support Mac and Ubuntu-based operating systems (we do not support Windows).

Requirements

Please ensure your operating system has the following software installed:

  • Git- seeGitHub's tutorialfor installation

  • Node.js(v10+) - usenvmto install it on any OS

    • After installingnvmyou will need to runnvm install node
    • We also recommend you installyarn,which is an alternative tonpm
  • MongoDB(v3.x+):

    • Mac (viabrew):brew tap mongodb/brew && brew install mongodb-community && brew services start mongodb-community.

    • Ubuntu:

      sudo apt-key adv --keyserver hkp://keyserver.ubuntu:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
      echo"deb http://repo.mongodb.org/apt/ubuntu"$(lsb_release -sc)"/mongodb-org/3.4 multiverse"|sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
      sudo apt-get update
      sudo apt-get -y install mongodb-org
  • Redis(v4.x+):

    • Mac (viabrew):brew install redis && brew services start redis

    • Ubuntu:

      sudo add-apt-repository -y ppa:chris-lea/redis-server
      sudo apt-get update
      sudo apt-get -y install redis-server

Install

npm:

npm install -g lad

yarn:

yarn global add lad

Usage

Create a project

lad new-project
cdnew-project

Development

To begin, try typingnpm start(oryarn start) on command line. This will display to you all the scripts you can run.

Thestartscript (among many others) usesnpsandnps-utilsunder the hood. This helps to keep scripts very developer-friendly, and rids the need to write in JSON syntax.

This script accepts a<task>argument, whereas a task ofallwill spawn, watch, and re-compile all of themicroservicesmentioned above.

Just openhttp://localhost:3000for testing!

npm:

npm start all

yarn:

yarn start all
Debugging
  • DEBUG- debug usingdebugoutput (widely adopted package in the community for debugging across all Node packages):

    DEBUG=*...
  • NODE_DEBUG- debugnodeinternal modules:

    NODE_DEBUG=*...
  • MONGOOSE_DEBUG- debug Mongoose raw database operation output:

    MONGOOSE_DEBUG=true...
  • TRANSPORT_DEBUG- debug Nodemailer transport:

    TRANSPORT_DEBUG=true...
  • REDIS_MONITOR- debug Redis usingMONITOR(uses@ladjs/redisand passestruefor themonitorargument):

    REDIS_MONITOR=true...
  • REDIS_FRIENDLY_ERROR_STACK- debug Redis with friendly error stack messages (seeshowFriendlyErrorStackoption ofioredis)

    REDIS_FRIENDLY_ERROR_STACK=true...

Production

We strongly recommend usingSemaphoreCI,PM2,andDigital Oceanfor production deployment.

  1. We've provided you with a preconfiguredecosystem.jsondeployment file.You will need to modify this file with your server's IP, hostname, and other metadata if needed.

  2. Make sure that your project's assets are built withNODE_ENV=productionflag, e.g.NODE_ENV=production npm run build(or with yarn asyarn build);this creates abuild/rev-manifest.jsonfile perkoa-manifest-rev.

  3. You can test this locally by installingPM2globally withnpmoryarn,and then running the following command:

    NODE_ENV=production pm2 start
  4. See theContinuous Integration and Code CoverageandTutorialssections below for instructions on how to setup continuous integration, code coverage, and deployment.

  5. If you specify an environment variable value forAWS_CF_DOMAINandNODE_ENV=productionis set then your assets will need to be published to Amazon S3/Cloudfront. To do so runnpm start publish-assets(or with yarn asyarn start publish-assets). This command automatically setsNODE_ENV=productionfor you as well viacross-env.

Provisioning

See theansiblefolder for ourAnsibleconfiguration and playbooks, which we use to provision servers with.

We recommend you to installyamllintand configure it in your editor while working withAnsibleplaybooks.

Also note thatansible-lintis a helpful linting tool you can use if you plan on making changes to playbooks. Note that our current playbooks have several existing lint errors.

First you must provision Ubuntu 18.04 LTS 64-bit server(s) usingDigital Ocean,Linode,Vultr,or your host of choice. These newly provisioned server(s) should have your SSH key automatically added.

Follow theDeploymentguide below for automatic provisioning and deployment instructions.

Deployment
  1. Set up host configuration by copying thehosts.ymlfile template:

    cp ansible/playbooks/templates/hosts.yml hosts.yml
  2. Edit this configuration and update the file with your newly created server aliases and IP addresses. You can add more than one host to each group if you are setting up load balancing. Refer to theNaming Conventiondocumentation for our recommended approach to server alias naming. Note that this file is automatically ignored by git. If you have a private repository and would like to commit this, then removehosts.ymlfrom the root.gitignorefile.

    vim hosts.yml
  3. Set up environment configuration by copying theenvfile template:

    cp ansible/playbooks/templates/env.env.production
  4. Edit this configuration and reference the officialLaddocumentation for a list of all available environment variables (or see.env.defaults).You will need to open this file in your preferred editorand set the values for any fields containingTODO,whereby you replaceTODOwith the appropriate value. Preserve double quotes where they are already defined.

    vim.env.production
  5. Generatepm2ecosystem filesusing our automatic template generator. We created anansible-playbook.jswhich loads the.env.productionenvironment variables rendered with@ladjs/envintoprocess.env,which then gets used in the playbooks. This is a superior, simple, and the only known dotenv approach we know of in Ansible. Newly createdecosystem-api.json,ecosystem-bree.json,ecosystem-web.jsonfiles will now be created for you in the root of the repository. If you ever more add or change IP addresses, you can simply re-run this command.

    node ansible-playbook ansible/playbooks/ecosystem.yml -l'localhost'
  6. Set up the web and API server(s) (seepatterns and ansible-playbook flags docsif you need help). If you completely (or partially) run this playbook (or any others below), then the second time you try to run it may not succeed. This is because we prevent root user access through security hardening. To workaround this, run the same command but without-e 'ansible_user=root'appended as it will default to thedevopsuser created.

    node ansible-playbook ansible/playbooks/http.yml -e'ansible_user=root'-l'http'
  7. Set up the Bree server(s):

    node ansible-playbook ansible/playbooks/bree.yml -e'ansible_user=root'-l'bree'
  8. Set up the Redis server:

    node ansible-playbook ansible/playbooks/redis.yml -e'ansible_user=root'-l'redis'
  9. Set up the Mongo server:

    node ansible-playbook ansible/playbooks/mongo.yml -e'ansible_user=root'-l'mongo'
  10. Set up GitHub deployment keys for all the servers. Note that thedeployment-keysdirectory is ignored from git, so if you have a private repository and wish to commit it, then removedeployment-keysfrom the.gitignorefile.

    node ansible-playbook ansible/playbooks/deployment-keys.yml -l'http:bree'
  11. Go to your repository "Settings" page on GitHub, click on "Deploy keys", and then add a deployment key for each servers' deployment key copied to thedeployment-keysdirectory. If you're on macOS, you can use thepbcopycommand to copy each file's contents to your clipboard. Use tab completion for speed, and replace the server names and paths with yours:

    cat deployment-keys/api-1-li-dal.forwardemail.net.pub|pbcopy
    
    #
    #NOTE: repeat the above command for all servers
    #and after running the command, it will copy
    #the key to your clipboard for you to paste as
    #a new deploy key (make sure to use read-only access)
    #
  12. Set up PM2 deployment directories on all the servers:

    pm2 deploy ecosystem-web.json production setup
    pm2 deploy ecosystem-api.json production setup
    pm2 deploy ecosystem-bree.json production setup
  13. Create a SSL certificate atNamecheap(we recommend a 5 year wildcard certificate), set up the certificate, and download and extract the ZIP file with the certificate (emailed to you) to your computer. We do not recommend using tools likeLetsEncryptandcertbotdue to complexity when you have (or scale to) a cluster of servers set up behind load balancers. In other words, we've tried approaches likelsyncdin combination withcrontabforcertbotrenewals and automatic checking. Furthermore, using this exposes the server(s) to downtime as ports80and443may need to be shut down so thatcertbotcan use them for certificate generation. This is not a reliable approach, and simply renewing certificates once a year is vastly simpler and also makes using load balancers trivial. Instead you can use a provider likeNamecheapto get a cheap SSL certificate, then run a few commands as we've documented below. This command will prompt you for an absolute file path to the certificates you downloaded. Renewed your certificate after 1 year? Simply follow this step again. Do not set a password on the certificate files. When using theopensslcommand (see Namecheap instructions), you need to use*.examplewith an asterisk followed by a period if you are registering a wildcard certificate.

    ansible-playbook ansible/playbooks/certificates.yml

    Important:If you renew or change certificates in the future, then after running the previous command, you will subsequently need to reload the processes as such:

    #
    #NOTE: See the "Important" note above BEFORE running this command.
    #This command ONLY APPLIES for certificate renewals/changes.
    #
    pm2 deploy ecosystem-web.json productionexec"pm2 reload web"
    pm2 deploy ecosystem-api.json productionexec"pm2 reload api"
  14. (Optional) Create a Google application credentials profile file and store it locally. You only need this if you want to support automatic translation. The following command will prompt you for the absolute file path (e.g./path/to/client-profile.json). See themandarindocs for more information.

    ansible-playbook ansible/playbooks/gapp-creds.yml -l'http:bree'
  15. Copy the.env.productionfile and create an AWS config file on the servers:

    node ansible-playbook ansible/playbooks/env.yml -l'http:bree'
  16. Run an initial deploy to all the servers:

    pm2 deploy ecosystem-web.json production
    pm2 deploy ecosystem-api.json production
    pm2 deploy ecosystem-bree.json production
  17. Save the process list on the servers so when if the server were to reboot, it will automatically boot back up the processes:

    pm2 deploy ecosystem-web.json productionexec"pm2 save"
    pm2 deploy ecosystem-api.json productionexec"pm2 save"
    pm2 deploy ecosystem-bree.json productionexec"pm2 save"
  18. Test by visiting your web and API server in your browser (click "proceed to unsafe" site and bypass certificate warning).

  19. Configure your DNS records for the web and API server hostnames and respective IP addresses.

  20. Test by visiting your web and API server in your browser (in an incognito window). There should not be any certificate warnings (similar to the one that occurred in step 15).

  21. (Optional) Remove the local.env.productionfile for security purposes. If you do this, then make sure you have a backup, or securely back up off the server in the future before destroying the server.

    rm.env.production
  22. (Optional) Remove the local certificate files you downloaded locally and specified in step 11. If you do this, then make sure you have a backup, or securely back up off the server in the future before destroying the server.

  23. Finished. If you need to deploy again, then push your changes to GitHubmasterbranch and then follow step 14 again. We recommend you to read theAnsible getting started guide,as it provides you with insight into commands likeansible all -a "echo hello"which can be run across all or specific servers.

Tests

We useavaandnycfor testing and code coverage.

npm:

npmtest

yarn:

yarntest

Configuration

Environment Variables

We have made configuration of your Lad project easy through adotenvconfiguration package called@ladjs/env,perTwelve-Factor.

We use the following three packages to manage configuration:

  • dotenv-extended- allows us to craft a.envdefinition (otherwise known as a "schema" ) in a file named.env.schema
  • mustache- allows us to use theMustache templating languagein our.envand.env.defaultsconfiguration files
  • dotenv-parse-variables- automatically parses variable types fromprocess.env(e.g.FOO=4will setprocess.env.FOO = 4with aNumbervariable type instead of aString)

Configuration is managed by the following, in order of priority:

  1. Contents of the file atconfig/index.js(reads inprocess.envenvironment variables)
  2. Contents of the files in directories underconfig/environments/(sets defaults per environment, e.g. you can passNODE_ENV=stagingand it will load the file atconfig/environments/staging.js)
  3. Environment variables used to override defaults or set required ones (e.g.NODE_ENV=production)
  4. Environment configuration in.env
  5. Environment configuration in.env.defaults

Precedence is taken by the environment configuration files, environment variables, then the.envfile.

Basicallydotenvwon't set an environment variable if it already detects it was passed as an environment variable.

Take a look at theconfigfolder contents and also at the defaults at.env.defaults.

  • NODE_ENV- (options:development,productiondefault:development) - the node environment the app is running in
  • PROXY_PORT- (default:8080) - proxy port used to proxy requests (seeladjs/proxy)
  • HTTP_PROTOCOL- (defaults:httprecommend:https) - protocol used for http requests
  • HTTP_PORT- (defaults:80recommend:443) - http port used for http requests
  • WEB_PROTOCOL- (default:http) -ladjs/webapplication protocol
  • WEB_HOST- (default:localhost) -ladjs/webapplication host
  • WEB_PORT- (default:3000) -ladjs/webapplication port
  • WEB_URL- (default:{{WEB_PROTOCOL}}://{{WEB_HOST}}:{{WEB_PORT}}) - web application absolute URI
  • WEB_SSL_KEY_PATH-ladjs/webfile path to your SSL key file
  • WEB_SSL_CERT_PATH-ladjs/webfile path to your SSL certificate file
  • WEB_SSL_CA_PATH-ladjs/webfile path to your SSL certificate authority file
  • API_HOST- (default:localhost) -ladjs/apihost
  • API_PORT- (default:4000) -ladjs/apiport
  • API_PROTOCOL- (default:httprecommend:https) -ladjs/apiprotocol
  • API_URL- (default:{{API_PROTOCOL}}://{{API_HOST}}:{{API_PORT}}) -ladjs/apiabsolute URI
  • API_SSL_KEY_PATH-ladjs/apifile path to your SSL key file
  • API_SSL_CERT_PATH-ladjs/apifile path to your SSL certificate file
  • API_SSL_CA_PATH-ladjs/apifile path to your SSL certificate authority file
  • API_RATELIMIT_WHITELIST-ladjs/apiratelimiter whitelisted ips (see:koa-simple-ratelimit)
  • APP_NAME- (default:Lad) - application name (seeusage)
  • APP_COLOR- application color theme (seeusage)
  • TWITTER- (default:@niftylettuce) twitter handle
  • SEND_EMAIL- (default:false) - whether to send email or preview (seeoutbound email configuration)
  • TRANSPORT_DEBUG- (default:false) - email transport debug logging (seedebugging)
  • EMAIL_DEFAULT_FROM- (default:[email protected]) - default emailfromaddress
  • SHOW_STACK- (default:true) - whether or not to output a stack trace when logging (seecabinjs options)
  • SHOW_META- (default:true) - whether or not to output metadata to logger methods (seecabinjs options)
  • SUPPORT_REQUEST_MAX_LENGTH- (default:500) - support request max message size in characters
  • ERROR_HANDLER_BASE_URL- (default:{{WEB_URL}}) error handling base url (seekoa-better-error-handler)
  • I18N_SYNC_FILES- (default:true) - sync locale information across all files (seeladjs/i18n options)
  • I18N_AUTO_RELOAD- (default:false) - watch for changes in json files to reload locale on updates (seeladjs/i18n options)
  • I18N_UPDATE_FILES- (default:true) - write new locale information to disk (seeladjs/i18n options)
  • AUTH_LOCAL_ENABLED- (default:true) - enable passport local strategy (seeladjs/passport)
  • AUTH_FACEBOOK_ENABLED- (default:false) - enable authenticating with Facebook using the OAuth 2.0 (seeladjs/passport)
  • AUTH_TWITTER_ENABLED- (default:false) - enable authenticating with Twitter using the OAuth 1.0 (seeladjs/passport)
  • AUTH_GOOGLE_ENABLED- (default:false) - enable authenticating with Google using OAuth 2.0 (seegoogle auth)
  • AUTH_GITHUB_ENABLED- (default:false) - enable authenticating with Github using OAuth 2.0 (seeladjs/passport)
  • AUTH_LINKEDIN_ENABLED- (default:false) - enable authenticating with LinkedIn using OAuth 1.0 (seeladjs/passport)
  • AUTH_INSTAGRAM_ENABLED- (default:false) - enable authenticating with Instagram using OAuth 2.0 (seeladjs/passport)
  • AUTH_OTP_ENABLED- (default:false) - enable authenticating with OTP, a form of two-factor authentication (seeladjs/passport)
  • AUTH_STRIPE_ENABLED- (default: false) - enable authenticating with Stripe using OAuth 2.0 (seeladjs/passport)
  • GOOGLE_CLIENT_ID- google oauth2 client id (seegoogle auth)
  • GOOGLE_CLIENT_SECRET- google oauth2 secret (seegoogle auth)
  • GOOGLE_CALLBACK_URL- google oauth2 callback url (seegoogle auth)
  • GOOGLE_APPLICATION_CREDENTIALS- path to google cloud platform credentials (seegcp credentials)
  • GITHUB_CLIENT_ID- github oauth client id (seeladjs/passport)
  • GITHUB_CLIENT_SECRET- github oauth secret (seeladjs/passport)
  • GITHUB_CALLBACK_URL- github oauth callback URL (seeladjs/passport)
  • POSTMARK_API_TOKEN- postmark api token (seeoutbound email configuration)
  • CODECOV_TOKEN- codecov api token (seecontinuous integration and code coverage)
  • MONGO_USER- mongodb username
  • MONGO_PASS- mongodb password
  • MONGO_HOST- (default:localhost) - mongodb hostname
  • MONGO_PORT- (default:27017) - mongodb port
  • MONGO_NAME- (default:{{APP_NAME}}_{{NODE_ENV}}) - mongodb name
  • MONGO_URI- (default:mongodb://{{MONGO_HOST}}:{{MONGO_PORT}}/{{MONGO_NAME}}) - mongodb connection URI
  • WEB_MONGO_USER-ladjs/webmongodb username
  • WEB_MONGO_PASS-ladjs/webmongodb password
  • WEB_MONGO_HOST-ladjs/webmongodb hostname
  • WEB_MONGO_NAME-ladjs/webmongodb name
  • WEB_MONGO_PORT-ladjs/webmongodb port
  • WEB_MONGO_URI-ladjs/webmongodb connection URI
  • API_MONGO_USER-ladjs/apimongodb username
  • API_MONGO_PASS-ladjs/apimongodb password
  • API_MONGO_HOST-ladjs/apimongodb hostname
  • API_MONGO_NAME-ladjs/apimongodb name
  • API_MONGO_PORT-ladjs/apimongodb port
  • API_MONGO_URI-ladjs/apimongodb connection URI
  • BREE_MONGO_USER-breejs/breemongodb username
  • BREE_MONGO_PASS-breejs/breemongodb password
  • BREE_MONGO_HOST-breejs/breemongodb hostname
  • BREE_MONGO_NAME-breejs/breemongodb name
  • BREE_MONGO_PORT-breejs/breemongodb port
  • BREE_MONGO_URI-breejs/breemongodb connection URI
  • REDIS_PORT- (default:6379) - redis port
  • REDIS_HOST- (default:localhost) - redis hostname
  • REDIS_PASSWORD- redis password
  • WEB_REDIS_PORT-ladjs/webredis port
  • WEB_REDIS_HOST-ladjs/webredis hostname
  • WEB_REDIS_PASSWORD-ladjs/webredis password
  • API_REDIS_PORT-ladjs/apiredis port
  • API_REDIS_HOST-ladjs/apiredis hostname
  • API_REDIS_PASSWORD-ladjs/apiredis password
  • BREE_REDIS_PORT-breejs/breeredis port
  • BREE_REDIS_HOST-breejs/breeredis hostname
  • BREE_REDIS_PASSWORD-breejs/breeredis password
  • MANDARIN_REDIS_PORT-mandarinredis port
  • MANDARIN_REDIS_HOST-mandarinredis hostname
  • MANDARIN_REDIS_PASSWORD-mandarinredis password
  • CERTBOT_WELL_KNOWN_NAME- letsencrypt wellknown name (seecertbot options)
  • CERTBOT_WELL_KNOWN_CONTENTS- letsencrypt wellknown contents (seecertbot options)
  • VERIFICATION_PIN_TIMEOUT_MS- (default:5m) - email verification pin expiry
  • VERIFICATION_PIN_EMAIL_INTERVAL_MS- (default:1m) - email verification pin email interval
  • API_SECRETS- (default:secret) - list of restricted api secrets
  • CACHE_RESPONSES- (default:false) - cache specified responses (seeladjs/koa-cache-responses)
  • SLACK_API_TOKEN- slack api token (seeslack web api)

SSL Configuration

To configure SSL for the web or API server simply set them in your.envfile or pass them as environment variables.

Web server:

  • WEB_PROTOCOL- you must set this tohttps
  • WEB_SSL_KEY_PATH- file path to your SSL key file (e.g./home/deploy/.ssl/web-key.pem)
  • WEB_SSL_CERT_PATH- file path to your SSL certificate file (e.g./home/deploy/.ssl/web-cert.pem)
  • WEB_SSL_CA_PATH(optional) - file path to your SSL certificate authority file (e.g./home/deploy/.ssl/web-ca-cert.pem)

API server:

  • API_PROTOCOL- you must set this tohttps
  • API_SSL_KEY_PATH- file path to your SSL key file (e.g./home/deploy/.ssl/api-key.pem)
  • API_SSL_CERT_PATH- file path to your SSL certificate file (e.g./home/deploy/.ssl/api-cert.pem)
  • API_SSL_CA_PATH(optional) - file path to your SSL certificate authority file (e.g./home/deploy/.ssl/api-ca-cert.pem)

Outbound Email Configuration

By default in the development environment we simply render the email in your browser.

However in other environments such as production, you definitely want emails to be sent.

We built-in support for Postmark by default (though you can swap in your owntransportprovider in thejobs/email.jsfile):

  1. Go tohttps://postmarkapp– Start Free Trial

  2. Create a free trial account, then click Get Started, and proceed to create a "Server" and "Sender Signature"

  3. Copy/paste the "Server API token" under "Credentials" in your.envfile (example below)

    -POSTMARK_API_TOKEN=
    +POSTMARK_API_TOKEN=ac6657eb-2732-4cfd-915b-912b1b10beb1
  4. Modify theSEND_EMAILvariable in.envfromfalsetotrue

Favicon and Touch Icon Configuration

You can customize the favicon and touch icons – just generate a new set athttps://realfavicongenerator.netand overwrite the existing in theassetsfolder.

Just make sure that any relative paths match up in theassets/browserconfig.xmlandassets/manifest.jsonfiles.

Authentication Methods

We use Lad's auth package under the hood; so if you want to configure authentication providers you'll want to read more or contribute to@ladjs/auth.

Google Auth

In order to add Google sign-in to your app (so users can log in with their Google account):

  1. Go tohttps://console.developers.google– Create a project (and fill out your project information – if you need a 120x120px default image,you can use this onewith a CDN path ofhttps://cdn.rawgit /ladjs/lad/82d38d64/media/lad-120x120.png

  2. Under your newly created project, go to Credentials – Create credentials – OAuth client ID – Web application

  3. Set "Authorized JavaScript origins" tohttp://yourdomain(replace with your domain) and alsohttp://localhost:3000(for local development)

  4. Set "Authorized redirect URIs" tohttp://yourdomain /auth/google/ok(again, replace with your domain) and alsohttp://localhost:3000/auth/google/ok(again, for local development)

  5. Copy and paste the newly created key pair for respective properties in your.envfile (example below)

    -GOOGLE_CLIENT_ID=
    +GOOGLE_CLIENT_ID=424623312719-73vn8vb4tmh8nht96q7vdbn3mc9pd63a.apps.googleusercontent
    -GOOGLE_CLIENT_SECRET=
    +GOOGLE_CLIENT_SECRET=Oys6WrHleTOksqXTbEY_yi07
  6. In.env,make sure thatAUTH_GOOGLE_ENABLED=trueto enable this authentication method.

Translation Configuration

  1. Go tohttps://console.developers.google
  2. Enable the Google Translate API
  3. Copy your API key and set it as the environment variableGOOGLE_TRANSLATE_KEY=******

Continuous Integration and Code Coverage

We strongly recommend that you useSemaphoreCIfor continuous integration andCodecovfor code coverage.

Here are the simple steps required to setupSemaphoreCIwithCodecov:

  1. Go toSemaphoreCIand sign up for a free account

  2. Once your repository is pushed to GitHub, add it as a project on SemaphoreCI

  3. Configure your project on SemaphoreCI with the following build settings:

    Replacenpmwithyarnif you're usingyarnas your package manager

    • Language:JavaScript
    • Node.js version:10+(latest LTS)

      Note you can also add toSetupthe scriptnvm install latestto install latest version if SemaphoreCI does not provide it from the drop-down

    • Setup:npm install
    • Job 1:npm run test-coverage
    • After job:npm run coverage
  4. Go toCodecovand sign up for a free account

  5. Add your project on Codecov and copy to your clipboard the token

  6. Go to SemaphoreCI's Project Settings for your project and addCODECOV_TOKENas an environment variable (with the contents from your clipboard)

  7. Run a test build ( "Rebuild last revision" ) on SemaphoreCI and check to make sure your code coverage report uploads properly on Codecov

  8. Ensure yourREADME.mdfile has the build status and code coverage badges rendered properly (you will need to use a different badge link from each provider if your GitHub repository is private)

Amazon S3 and CloudFront Asset Setup

In order for your assets to get properly served in a production environment, you'll need to configure AWS:

  1. Go tohttps://console.aws.amazon /iam/home#security_credential‐ Access Keys – Create New Access Key

  2. Copy and paste the newly created key pair for respective properties in your.envfile (example below)

    -AWS_IAM_KEY=
    +AWS_IAM_KEY=AKIAJMH22P6W674YFC7Q
    -AWS_IAM_SECRET=
    +AWS_IAM_SECRET=9MpR1FOXwPEtPlrlU5WbHjnz2KDcKWSUcB+C5CpS
  3. Enable your API by clicking on Overview and then clicking the Enable button

  4. Go tohttps://console.aws.amazon /s3/home– Create Bucket

  5. Create a bucket and copy/paste its name for the property in.env(example below)

    -AWS_S3_BUCKET=
    +AWS_S3_BUCKET=lad-development
  6. Go tohttps://console.aws.amazon /cloudfront/home– Create Distribution – Get Started

  7. Set "Origin Domain Name" equal to your S3 bucket name (their autocomplete drop-down will help you find it)

  8. Leave the remaining defaults as is (some fields might be blank, this is OK)

  9. Copy/paste the newly created Distribution ID and Domain Name for respective properties in your.envfile (example below)

    -AWS_CF_DI=
    +AWS_CF_DI=E2IBEULE9QOPVE
    -AWS_CF_DOMAIN=
    +AWS_CF_DOMAIN=d36aditw73gdrz.cloudfront.net

Tutorials

Community

Architecture

The following bash output is the directory structure and organization of Lad:

tree template -I"build|node_modules|coverage|test"
template
├── LICENSE
├── README
├── ansible
│ ├── playbooks
│ │ ├── aws-credentials.yml
│ │ ├── bree.yml
│ │ ├── certificates.yml
│ │ ├── deployment-keys.yml
│ │ ├── ecosystem.yml
│ │ ├── env.yml
│ │ ├── gapp-creds.yml
│ │ ├── http.yml
│ │ ├── mongo.yml
│ │ ├── node.yml
│ │ ├── Python.yml
│ │ ├── redis.yml
│ │ ├── security.yml
│ │ ├── ssh-keys.yml
│ │ └── templates
│ │ ├── aws-credentials.j2
│ │ ├── before.rules.j2
│ │ ├── ecosystem-api.json.j2
│ │ ├── ecosystem-bree.json.j2
│ │ ├── ecosystem-web.json.j2
│ │ ├── env
│ │ ├── hosts.yml
│ │ └── security-limits.d-mongod.conf
│ └── requirements.yml
├── ansible-playbook.js
├── ansible.cfg
├── api.js
├── app
│ ├── controllers
│ │ ├── api
│ │ │ ├── index.js
│ │ │ └── v1
│ │ │ ├── index.js
│ │ │ ├── log.js
│ │ │ └── users.js
│ │ ├── index.js
│ │ └── web
│ │ ├── admin
│ │ │ ├── index.js
│ │ │ └── users.js
│ │ ├── auth.js
│ │ ├── index.js
│ │ ├── my-account.js
│ │ ├── otp
│ │ │ ├── disable.js
│ │ │ ├── index.js
│ │ │ ├── keys.js
│ │ │ ├── recovery.js
│ │ │ └── setup.js
│ │ ├── report.js
│ │ └── support.js
│ ├── models
│ │ ├── index.js
│ │ ├── inquiry.js
│ │ └── user.js
│ └── views
│ ├── 404.pug
│ ├── 500.pug
│ ├── _breadcrumbs.pug
│ ├── _footer.pug
│ ├── _nav.pug
│ ├── _pagination.pug
│ ├── _register-or-login.pug
│ ├── about.pug
│ ├── admin
│ │ ├── index.pug
│ │ └── users
│ │ ├── index.pug
│ │ └── retrieve.pug
│ ├── change-email.pug
│ ├── dashboard
│ │ └── index.pug
│ ├── donate.pug
│ ├── forgot-password.pug
│ ├── home.pug
│ ├── layout.pug
│ ├── my-account
│ │ ├── index.pug
│ │ ├── profile.pug
│ │ └── security.pug
│ ├── otp
│ │ ├── enable.pug
│ │ ├── keys.pug
│ │ ├── login.pug
│ │ └── setup.pug
│ ├── privacy.pug
│ ├── register-or-login.pug
│ ├── reset-password.pug
│ ├── spinner
│ │ ├── 1.pug
│ │ ├── 10.pug
│ │ ├── 11.pug
│ │ ├── 2.pug
│ │ ├── 3.pug
│ │ ├── 4.pug
│ │ ├── 5.pug
│ │ ├── 6.pug
│ │ ├── 7.pug
│ │ ├── 8.pug
│ │ ├── 9.pug
│ │ └── spinner.pug
│ ├── support.pug
│ ├── terms.pug
│ └── verify.pug
├── assets
│ ├── browserconfig.xml
│ ├── css
│ │ ├── _btn-auth.scss
│ │ ├── _custom.scss
│ │ ├── _email.scss
│ │ ├── _markdown.scss
│ │ ├── _responsive-backgrounds.scss
│ │ ├── _responsive-borders.scss
│ │ ├── _responsive-rounded.scss
│ │ ├── _swal2.scss
│ │ ├── _variables.scss
│ │ └── app.scss
│ ├── fonts
│ ├── img
│ │ ├── android-chrome-192x192.png
│ │ ├── android-chrome-384x384.png
│ │ ├── apple-touch-icon.png
│ │ ├── favicon-16x16.png
│ │ ├── favicon-32x32.png
│ │ ├── favicon.ico
│ │ ├── github-logo.svg
│ │ ├── google-logo.svg
│ │ ├── logo-square.svg
│ │ ├── mstile-150x150.png
│ │ ├── social.png
│ │ └── twitter.png
│ ├── js
│ │ ├── core.js
│ │ ├── logger.js
│ │ └── uncaught.js
│ ├── robots.txt
│ └── site.webmanifest
├── bree.js
├── config
│ ├── api.js
│ ├── bree.js
│ ├── cookies.js
│ ├── env.js
│ ├── filters.js
│ ├── i18n.js
│ ├── index.js
│ ├── koa-cash.js
│ ├── locales.js
│ ├── logger.js
│ ├── meta.js
│ ├── phrases.js
│ ├── utilities.js
│ └── web.js
├── emails
│ ├── _content.pug
│ ├── _footer.pug
│ ├── _nav.pug
│ ├── account-update
│ │ ├── html.pug
│ │ └── subject.pug
│ ├── change-email
│ │ ├── html.pug
│ │ └── subject.pug
│ ├── inquiry
│ │ ├── html.pug
│ │ └── subject.pug
│ ├── layout.pug
│ ├── recovery
│ │ ├── html.pug
│ │ └── subject.pug
│ ├── reset-password
│ │ ├── html.pug
│ │ └── subject.pug
│ ├── two-factor-reminder
│ │ ├── html.pug
│ │ └── subject.pug
│ ├── verify
│ │ ├── html.pug
│ │ └── subject.pug
│ └── welcome
│ ├── html.pug
│ └── subject.pug
├── env
├── gitignore
├── gulpfile.js
├── helpers
│ ├── email.js
│ ├── get-email-locals.js
│ ├── i18n.js
│ ├── logger.js
│ ├── markdown.js
│ ├── passport.js
│ ├── policies.js
│ ├── send-verification-email.js
│ └── to-object.js
├── index.js
├──jobs
│ ├── account-updates.js
│ ├── index.js
│ ├── translate-markdown.js
│ ├── translate-phrases.js
│ ├── two-factor-reminder.js
│ └── welcome-email.js
├── lad.sh
├── locales
│ ├── ar.json
│ ├── cs.json
│ ├── da.json
│ ├── de.json
│ ├── en.json
│ ├── es.json
│ ├── fi.json
│ ├── fr.json
│ ├── he.json
│ ├── hu.json
│ ├── id.json
│ ├── it.json
│ ├── ja.json
│ ├── ko.json
│ ├── nl.json
│ ├── no.json
│ ├── pl.json
│ ├── pt.json
│ ├── ru.json
│ ├── sv.json
│ ├── th.json
│ ├── tr.json
│ ├── uk.json
│ ├── vi.json
│ └── zh.json
├── nodemon.json
├── package-scripts.js
├── package.json
├── proxy.js
├── routes
│ ├── api
│ │ ├── index.js
│ │ └── v1
│ │ └── index.js
│ ├── index.js
│ └── web
│ ├── admin.js
│ ├── auth.js
│ ├── index.js
│ ├── my-account.js
│ └── otp.js
├── template
├── web.js
├── yarn-error.log
└── yarn.lock

42 directories, 212 files

Principles

Lad is designed according to these principles:

  1. Always be developer-friendly
  2. Adhere toMVC,Unix,KISS,DRY,YAGNI,Twelve Factor,Occam's razor,anddogfooding
  3. Target the scrappy, bootstrapped, andramen-profitablehacker

Related

Contributing

Interesting in contributing to this project or testing early releases?

  1. Follow all of the aboveRequirements

  2. You will need to fork and clone this repository locally

  3. After forking, follow these steps:

    cdlad
    yarn install
    cdtemplate
    yarn install
    yarn start

If you'd like to preview changes to theREADME.mdfile, you can usedocute.

yarn global add docute-cli
cdlad
docute./

Then visithttp://localhost:8080in your browser.

Contributors

Name Website
Nick Baugh http://niftylettuce
Shaun Warman https://shaunwarman /

Trademark Notice

Lad, Lass, Cabin, Lipo, and their respective logos are trademarks of Niftylettuce LLC. These trademarks may not be reproduced, distributed, transmitted, or otherwise used, except with the prior written permission of Niftylettuce LLC. If you are seeking permission to use these trademarks, then pleasecontact us.

License

MIT©Nick Baugh

#