Last active
August 29, 2015 14:15
-
-
Save rxw1/aab3270c7c8ffabb18d2 to your computer and use it in GitHub Desktop.
[koa] try catch pg connect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
//jshint esnext:true | |
'use strict'; | |
var koa = require('koa'); | |
var cors = require('koa-cors'); | |
var pg = require('koa-pg'); | |
var app = koa(); | |
var DATABASE = process.env.DATABASE || 'postgres://asdsf@localhost/database'; | |
var PORT = process.env.PORT || 3333; | |
app.use(cors()); | |
app.use(function *(next) { | |
try { | |
yield next; | |
this.status = 200; | |
} catch (err) { | |
this.status = 503; | |
throw new Error('DB FAILURE'); | |
} | |
}); | |
app.use(pg(DATABASE)); | |
app.listen(PORT); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment