Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update dependencies #4

Merged
merged 4 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict';

module.exports = {
PORT: process.env.PORT || 8080,
CLIENT_ORIGIN: process.env.CLIENT_ORIGIN || 'http://localhost:3000',
DATABASE_URL:
PORT: process.env.PORT || 8080,
CLIENT_ORIGIN: process.env.CLIENT_ORIGIN || 'http://localhost:3000',
DATABASE_URL:
process.env.DATABASE_URL || 'mongodb://localhost/thinkful-backend',
TEST_DATABASE_URL:
TEST_DATABASE_URL:
process.env.TEST_DATABASE_URL ||
'mongodb://localhost/thinkful-backend-test'
// DATABASE_URL:
// process.env.DATABASE_URL || 'postgres://localhost/thinkful-backend',
// TEST_DATABASE_URL:
// process.env.TEST_DATABASE_URL ||
// 'postgres://localhost/thinkful-backend-test'
// DATABASE_URL:
// process.env.DATABASE_URL || 'postgres://localhost/thinkful-backend',
// TEST_DATABASE_URL:
// process.env.TEST_DATABASE_URL ||
// 'postgres://localhost/thinkful-backend-test'
};
20 changes: 11 additions & 9 deletions db-knex.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
'use strict';

const createKnex = require('knex');

const {DATABASE_URL} = require('./config');

let knex = null;

function dbConnect(url = DATABASE_URL) {
knex = createKnex({
client: 'pg',
connection: url
});
knex = createKnex({
client: 'pg',
connection: url
});
}

function dbDisconnect() {
return knex.destroy();
return knex.destroy();
}

function dbGet() {
return knex;
return knex;
}

module.exports = {
dbConnect,
dbDisconnect,
dbGet
dbConnect,
dbDisconnect,
dbGet
};
40 changes: 21 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
'use strict';

const express = require('express');
const cors = require('cors');
const morgan = require('morgan');

const {PORT, CLIENT_ORIGIN} = require('./config');
const {dbConnect} = require('./db-mongoose');
const { PORT, CLIENT_ORIGIN } = require('./config');
const { dbConnect } = require('./db-mongoose');
// const {dbConnect} = require('./db-knex');

const app = express();

app.use(
morgan(process.env.NODE_ENV === 'production' ? 'common' : 'dev', {
skip: (req, res) => process.env.NODE_ENV === 'test'
})
morgan(process.env.NODE_ENV === 'production' ? 'common' : 'dev', {
skip: (req, res) => process.env.NODE_ENV === 'test'
})
);

app.use(
cors({
origin: CLIENT_ORIGIN
})
cors({
origin: CLIENT_ORIGIN
})
);

function runServer(port = PORT) {
const server = app
.listen(port, () => {
console.info(`App listening on port ${server.address().port}`);
})
.on('error', err => {
console.error('Express failed to start');
console.error(err);
});
const server = app
.listen(port, () => {
console.info(`App listening on port ${server.address().port}`);
})
.on('error', err => {
console.error('Express failed to start');
console.error(err);
});
}

if (require.main === module) {
dbConnect();
runServer();
dbConnect();
runServer();
}

module.exports = {app};
module.exports = { app };