Skip to content

Commit

Permalink
Deploying to heroku. #30
Browse files Browse the repository at this point in the history
  • Loading branch information
ansonhwo committed Feb 16, 2017
1 parent b2e8e27 commit b2a618b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
33 changes: 24 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
const express = require('express')
const bodyParser = require('body-parser')
const knex = require('knex')({
client: 'postgresql',
connection: {
user: 'super',
database: 'eventinfo'
}
})

let knex
if (process.env.PORT) {
// Production
knex = require('knex')({
client: 'postgresql',
connection: process.env.PORT
})
}
else {
// Development
knex = require('knex')({
client: 'postgresql',
connection: {
user: 'super',
database: 'eventinfo'
}
})
}

const app = express()

const PORT = process.env.PORT || 9999

app.use(express.static('public'))
app.use(bodyParser.json())

Expand Down Expand Up @@ -52,7 +67,7 @@ app.get('/events/reg/:email', (req, res) => {

app.post('/events/create', (req, res) => {
const formData = req.body

for (key in formData) {
if (!formData[key]) delete formData[key]
}
Expand Down Expand Up @@ -103,4 +118,4 @@ app.put('/users/reg', (req, res) => {
.catch((err) => res.sendStatus(404))
})

app.listen(9999, () => { console.log('Listening on 9999') })
app.listen(PORT, () => console.log(`Listening on ${PORT}`))
12 changes: 12 additions & 0 deletions knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ exports.development = {
tableName: 'knex_migrations'
}
}

exports.production = {
client: 'postgresql',
connection: process.env.DATABASE_URL,
seeds: {
directory: './seeds/dev'
},
migrations: {
directory: './migrations',
tableName: 'knex_migrations'
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"start": "node .",
"watch": "nodemon .",
"heroku-postbuild": "run-s migrate seed:run",
"migrate:make": "knex migrate:make",
"migrate": "knex migrate:latest",
"rollback": "knex migrate:rollback",
Expand All @@ -31,6 +32,7 @@
"vue": "^2.1.8"
},
"devDependencies": {
"nodemon": "^1.11.0"
"nodemon": "^1.11.0",
"npm-run-all": "^4.0.1"
}
}

0 comments on commit b2a618b

Please sign in to comment.