/dotcom

mbta.com

Primary LanguageElixirMIT LicenseMIT

Dotcom

The new face of https://www.mbta.com/.

Supported browsers

We strive to support all users – but the variety of browsers, operating systems and devices available necessitates a more intentioned approach. Generally speaking, Dotcom supports the stable latest releases of all major web browsers (Chrome, Safari, Firefox, Microsoft Edge, and Internet Explorer 11) and platforms (Windows, MacOS, iOS, Android). Other interfaces using the underlying engines of the aforementioned browsers – that's WebKit, Blink, Gecko – are not explicitly supported but are expected to function correctly.

From a development standpoint, polyfills and code transforms are implemented via Babel with the target browsers noted in the site .browserslistrc.

Getting Started

  1. Request a V3 API key at https://dev.api.mbtace.com/. Note that, at any given time, the site may not be compatible with the very latest API version - as of Jan 2021 the site is using API version 2019-07-01. After receiving an API key, you may need to edit the version of your key to match the site's API version.

  2. Install Homebrew:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  3. Install asdf package version manager

    • Follow the instructions on https://github.com/asdf-vm/asdf

    • Install the necessary tools to set up asdf plugins:

      brew install coreutils automake autoconf openssl libyaml readline libxslt libtool unixodbc gpg
      
    • Add asdf plugins

      asdf plugin-add erlang
      asdf plugin-add elixir
      asdf plugin-add nodejs
      

      You can verify the plugins were installed with asdf plugin-list

    • Import the Node.js release team's OpenPGP keys to install 'nodejs' plugin:

      bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring
      

      If you run into problems, you might have to update the import-release-team-keyring script.

    • If running OSX 10.15 Catalina, run export MACOSX_DEPLOYMENT_TARGET=10.14. This works around a known issue with compiling versions of Erlang prior to 22.1.4.

    • If running OSX 11 Big Sur, you will need to modify the source directly. (This comment captures the issue/solution). As of Jan 2021, we use erlang 22.3.3, and the filenames below reflect this.

      First, run the install. Navigate to the erlang directory and unzip the source.

      asdf install
      cd ~/.asdf/plugins/erlang/kerl-home/archives
      tar zxvf OTP-22.3.3.tar.gz
      

      Modify ~/.asdf/plugins/erlang/kerl-home/archives/otp-OTP-23.1.4/make/configure.in line 415 to read:

      #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > $int_macosx_version && false
      

      Re-tar the directory:

      rm OTP-22.3.3.tar.gz
      tar czvf OTP-22.3.3.tar.gz otp-OTP-22.3.3
      rm -rf otp-OTP-22.3.3
      

      Then re-run the erlang install:

      asdf install erlang 22.3.3
      
    • Note on Erlang version: while v24 resolves the compilation issue, we still need to use v22 as of Jan 2021.

    • Now, (if you haven't already in the OSX11 instructions above) run the install:

      asdf install
      
    • Verify that all the languages for our setup were installed:

      asdf current
      

      You should see the following output with versions specified from .tool-versions:

       elixir         <version> (set by ~/dotcom/.tool-versions)
       erlang         <version> (set by ~/dotcom/.tool-versions)
       nodejs         <version> (set by ~/dotcom/.tool-versions)
       ...
      

      If you are missing any versions, you should re-run asdf install. Related Github issue about asdf-erlang

      You may have to individually install each version

      asdf install plugin_name <version> (set by ~/dotcom/.tool-versions)
      

      If erlang is still missing you can run the following commands

       brew install openssl@1.1
       export KERL_CONFIGURE_OPTIONS="--without-javac --with-ssl=/usr/local/opt/openssl@1.1"
       brew install autoconf@2.69 && \
       brew link --overwrite autoconf@2.69 && \
       autoconf -V
      
  4. Install chromedriver (for Elixir acceptance tests using Wallaby)

    brew install --cask chromedriver
    

    Note: chromedriver requires Chrome to be installed. If you don't already have it, brew install --cask google-chrome is an easy way to install it.

  5. Install our Elixir dependencies. From the root of this repo:

    mix deps.get
    
  6. Install our Node dependencies. From the root of this repo:

    npm run install
    

    You won't see a node_modules folder at the root of this project -- this installs packages into apps/site/assets.

  7. Build the project:

    npm run build
    
    • If this fails try adding the following line to defp deps section in mix.exs:
    {:fs, git: "https://github.com/synrc/fs.git", override: true}
    

npm run build does several things: builds the Phoenix application assets, builds all the front-end assets, and then compiles the entire Elixir application.

  1. Set up required environment variables:
    cp .envrc.template .envrc
    
    Then uncomment the V3_API_KEY line and fill it in with the key you obtained in the first step. If you have direnv installed (recommended), it will automatically load and unload the environment using this file. If not, source .envrc will load or update the variables in your shell session manually.

For details on environment configuration, including optional variables, see ENVIRONMENT.md.

Running the Server

Start the server with mix phx.server

Then, visit the site at http://localhost:4001/

Algolia

Algolia powers our search features. Sometimes after content updates or GTFS releases we will find that the search results do not contain up-to-date results. When this happens you can re-index the Algolia data by running: mix algolia.update.

Additional Resources

New to the team, or looking for further developer resources?

Nested Applications