Skip to content

Commit

Permalink
docs: add heroku server guide
Browse files Browse the repository at this point in the history
closes #74
  • Loading branch information
patrickhulce committed Dec 3, 2019
1 parent 9365887 commit b23f2d6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/recipes/heroku-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Heroku-based LHCI Server

## Overview

The LHCI server can be run in any node environment with persistent disk storage or network access to a postgres database. Heroku offers a [free tier of hosting](https://www.heroku.com/pricing) that provides exactly this!

## Setting Up Your Repo

```bash
# Create a directory and repo for your heroku project
mkdir lhci-heroku && cd lhci-heroku && git init
# Setup the LHCI files
curl https://raw.githubusercontent.com/GoogleChrome/lighthouse-ci/master/docs/recipes/heroku-server/package.json > package.json
curl https://raw.githubusercontent.com/GoogleChrome/lighthouse-ci/master/docs/recipes/heroku-server/server.js > server.js
# Create the project's first commit
git add -A && git commit -m 'Initial commit'
```

## Setting Up Heroku

This assumes you've already signed up, created a heroku account, and installed the [heroku CLI](https://devcenter.heroku.com/articles/heroku-cli).

```bash
# Create a new project on heroku
heroku create
# Add a free database to your project
heroku addons:create heroku-postgresql:hobby-dev
# Deploy your code to heroku
git push heroku master
# Ensure heroku is running your app and open the URL
heroku ps:scale web=1
heroku open
```

## Updating LHCI

Updates are made to the LHCI server from time to time and you'll want to keep up! You can update your LHCI server on Heroku just by pushing a commit.

```bash
# Update LHCI
npm install --save @lhci/server@latest
# Create a commit with your update
git add -A && git commit -m 'update LHCI'
# Deploy your update to heroku
git push heroku master
```
10 changes: 10 additions & 0 deletions docs/recipes/heroku-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "lhci",
"version": "1.0.0",
"main": "server.js",
"dependencies": {
"@lhci/server": "0.3.x",
"pg": "^7.12.1",
"pg-hstore": "^2.3.3"
}
}
19 changes: 19 additions & 0 deletions docs/recipes/heroku-server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

const {createServer} = require('@lhci/server');

console.log('Starting server...');
createServer({
port: process.env.PORT,
storage: {
storageMethod: 'sql',
sqlDialect: 'postgres',
sqlConnectionSsl: true,
sqlConnectionUrl: process.env.DATABASE_URL,
},
}).then(({port}) => console.log('Listening on port', port));

0 comments on commit b23f2d6

Please sign in to comment.