Skip to content

Commit

Permalink
Heroku support (data-govt-nz#5)
Browse files Browse the repository at this point in the history
* Add heroku procfile

* Set the port

* Force the use of page param no full json set

* Return nothing

* Return page 1 on base

* Start the app via node

* Allow heroku to set the port for serving app
  • Loading branch information
camfindlay authored Feb 7, 2018
1 parent eb102e4 commit 724dc5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node web.js
8 changes: 6 additions & 2 deletions pager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var heredoc = require('heredoc')

var app = express();

// set the port of our application
// process.env.PORT lets the port be set by Heroku
var port = process.env.PORT || 8080;

var datajson = heredoc(function () {/*
{
"@context": "https://project-open-data.cio.gov/v1.1/schema/catalog.jsonld",
Expand Down Expand Up @@ -333,11 +337,11 @@ app.get('/', function (req, res) {
} else if (req.query.page == '2') {
res.send(page2);
} else {
res.send(datajson);
res.send(page1);
}
});


app.listen(3000, function () {
app.listen(port, function () {
console.log('Serve up a paginated example data.json');
});
8 changes: 6 additions & 2 deletions web.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const upload = multer({storage: multer.memoryStorage()})
*/
const GLOBAL_DATA = {};

// set the port of our application
// process.env.PORT lets the port be set by Heroku
const port = process.env.PORT || 3000;

app.use(bodyParser.urlencoded({extended: true}));

app.get('/', (req, res) => {
Expand Down Expand Up @@ -76,7 +80,7 @@ app.get('/api/:id/data.json', (req, res) => {
app.use('/static', express.static('static'))


app.listen(3000, () => console.log('Example app listening on port 3000!'))
app.listen(port, () => console.log('Example app listening on port 3000!'))

/**
* A simple utillity function for generating an (fake) GUID-4
Expand All @@ -87,4 +91,4 @@ function fakeID() {
v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
}

0 comments on commit 724dc5d

Please sign in to comment.