Skip to content

Commit

Permalink
Configure for deployment with zeit now (#1308)
Browse files Browse the repository at this point in the history
I'm experimenting with Zeit Now as another hosting option. These changes enable a working deployment.
  • Loading branch information
paulmelnikow authored Dec 4, 2017
1 parent 1eedd45 commit 9882a44
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
11 changes: 11 additions & 0 deletions doc/self-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ machine.
[shields.example.env]: ../shields.example.env


Zeit Now
--------

To deploy using Zeit Now:

```console
npm run build # Not sure why, but this needs to be run before deploying.
now
```


Server secrets
--------------

Expand Down
6 changes: 4 additions & 2 deletions lib/github-auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const path = require('path');
const crypto = require('crypto');
const log = require('./log');
const queryString = require('query-string');
Expand All @@ -13,8 +14,9 @@ const mapKeys = require('lodash.mapkeys');
// with a JsonSave object.
let githubUserTokens = {data: []};

function scheduleAutosaving() {
const githubUserTokensFile = './private/github-user-tokens.json';
function scheduleAutosaving(config) {
const { dir: persistenceDir } = config;
const githubUserTokensFile = path.resolve(persistenceDir, 'github-user-tokens.json');
autosave(githubUserTokensFile, {data: []}).then(save => {
githubUserTokens = save;
for (let i = 0; i < githubUserTokens.data.length; i++) {
Expand Down
3 changes: 3 additions & 0 deletions lib/server-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const config = {
cors: {
allowedOrigin,
},
persistence: {
dir: process.env.PERSISTENCE_DIR || './private',
},
services: {
github: {
baseUri: process.env.GITHUB_URL || 'https://api.github.com',
Expand Down
25 changes: 25 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "shields",
"files": [
"*.js",
"*.png",
"build/",
"frontend/",
"lib/",
"logo/",
"pages/",
"public/",
"static/",
"templates/",
"!**/*.spec.js",
"!**/*.integration.js"
],
"env": {
"PERSISTENCE_DIR": "/tmp/persistence",
"SHIELDS_ANALYTICS_FILE": "/tmp/analytics.json"
},
"type": "npm",
"engines": {
"node": "8.x"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"heroku-postbuild": "npm run build",
"analyze": "ANALYZE=true LONG_CACHE=false BASE_URL=https://img.shields.io npm run build",
"start:server": "node server 8080 ::",
"now-start": "node server",
"prestart": "npm run frontend-depcheck",
"start": "concurrently --names server,frontend \"ALLOWED_ORIGIN=http://localhost:3000 npm run start:server\" \"BASE_URL=http://[::]:8080 next dev\""
},
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ analytics.load();
analytics.scheduleAutosaving();
analytics.setRoutes(camp);

githubAuth.scheduleAutosaving();
githubAuth.scheduleAutosaving({ dir: config.persistence.dir });
if (serverSecrets && serverSecrets.gh_client_id) {
githubAuth.setRoutes(camp);
}
Expand Down

0 comments on commit 9882a44

Please sign in to comment.