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

Code Cleanup #15

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
34 changes: 15 additions & 19 deletions bin/create-config
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node
// Ghost Configuration for Heroku

var fs = require('fs');
var path = require('path');
var url = require('url');
const fs = require('fs'),
MCTaylor17 marked this conversation as resolved.
Show resolved Hide resolved
path = require('path'),
url = require('url');

var envValues = require('./common/env-values');
var appRoot = path.join(__dirname, '..');
const envValues = require('./common/env-values');
const appRoot = path.join(__dirname, '..');

function createConfig() {
var fileStorage, storage, storageOptions;
Expand Down Expand Up @@ -35,7 +35,7 @@ function createConfig() {
storage = {}
}

config = {
const config = {
url: process.env.PUBLIC_URL,
logging: {
level: "info",
Expand Down Expand Up @@ -72,34 +72,30 @@ function createConfig() {
}

function getMysqlConfig(connectionUrl) {
if (connectionUrl == null) {
if (connectionUrl === null) {
MCTaylor17 marked this conversation as resolved.
Show resolved Hide resolved
return {};
}

var dbConfig = url.parse(connectionUrl);
if (dbConfig == null) {
const dbConfig = url.parse(connectionUrl);
if (dbConfig === null) {
return {};
}

var dbAuth = dbConfig.auth ? dbConfig.auth.split(':') : [];
var dbUser = dbAuth[0];
var dbPassword = dbAuth[1];
const dbAuth = dbConfig.auth ? dbConfig.auth.split(':', 2) : [];
const [dbUser, dbPassword] = dbAuth;

if (dbConfig.pathname == null) {
var dbName = 'ghost';
} else {
var dbName = dbConfig.pathname.split('/')[1];
}
const dbName = (dbConfig.pathname === null) ? 'ghost' : dbConfig.pathname.split('/', 2)[1];
MCTaylor17 marked this conversation as resolved.
Show resolved Hide resolved

var dbConnection = {
const dbConnection = {
host: dbConfig.hostname,
port: dbConfig.port || '3306',
user: dbUser,
password: dbPassword,
database: dbName
};

return dbConnection;
}

var configContents = JSON.stringify(createConfig(), null, 2);
const configContents = JSON.stringify(createConfig(), null, 2);
fs.writeFileSync(path.join(appRoot, 'config.production.json'), configContents);
6 changes: 3 additions & 3 deletions bin/wait-for-db
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node

var mysql = require('../node_modules/mysql');
var envValues = require('./common/env-values');
const mysql = require('../node_modules/mysql'),
envValues = require('./common/env-values');

console.error(`Awaiting MySQL database…`);
pingDatabaseUntilConnected();

function pingDatabaseUntilConnected() {
var connection = mysql.createConnection(envValues.mysqlDatabaseUrl);
const connection = mysql.createConnection(envValues.mysqlDatabaseUrl);
connection.query('SELECT 1', function (error, results, fields) {
if (error) {
console.error(`Database not yet available: ${error.message}`);
Expand Down
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var ghost = require('ghost');
const ghost = require('ghost');

// Run a single Ghost process
ghost()
.then( ghostServer => ghostServer.start() )
.catch( error => {
console.error(`Ghost server error: ${error.message} ${error.stack}`);
console.error('Ghost server error:', error.message, error.stack);
MCTaylor17 marked this conversation as resolved.
Show resolved Hide resolved
process.exit(1);
});