Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Fix eslint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mordorreal committed Jun 4, 2016
1 parent 34c85c0 commit b54018a
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 94 deletions.
2 changes: 1 addition & 1 deletion html/email-templates/new_comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
</td>
<td class="user__name">
<div><a class="user__profile" href="#">Vladimiras Lekecinskas</a></div>
<div class="text-gray">on Friday 2nd February, 20:11<div>
<div class="text-gray">on Friday 2nd February, 20:11</div>
</td>
</tr>
</table>
Expand Down
44 changes: 22 additions & 22 deletions knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
try {
require('babel-register');
require('babel-polyfill');
} catch(e) {
} catch (e) {
// it's ok. might be already enabled
}

Expand All @@ -12,16 +12,16 @@ module.exports = {
development: {
client: 'postgresql',
connection: {
host : '127.0.0.1',
user : 'libertysoil',
password : 'libertysoil',
database : 'libertysoil',
charset : 'utf8'
host: '127.0.0.1',
user: 'libertysoil',
password: 'libertysoil',
database: 'libertysoil',
charset: 'utf8'
},
pool: {
min: 2,
max: 10,
ping: function (conn, cb) {
ping: (conn, cb) => {
conn.query('SELECT 1', cb);
}
},
Expand All @@ -33,16 +33,16 @@ module.exports = {
test: {
client: 'postgresql',
connection: {
host : '127.0.0.1',
user : 'libertysoil',
password : 'libertysoil',
database : 'libertysoil_test',
charset : 'utf8'
host: '127.0.0.1',
user: 'libertysoil',
password: 'libertysoil',
database: 'libertysoil_test',
charset: 'utf8'
},
pool: {
min: 2,
max: 10,
ping: function (conn, cb) {
ping: (conn, cb) => {
conn.query('SELECT 1', cb);
}
},
Expand All @@ -54,16 +54,16 @@ module.exports = {
travis: {
client: 'postgresql',
connection: {
host : '127.0.0.1',
user : 'postgres',
password : 'postgres',
database : 'libertysoil',
charset : 'utf8'
host: '127.0.0.1',
user: 'postgres',
password: 'postgres',
database: 'libertysoil',
charset: 'utf8'
},
pool: {
min: 2,
max: 10,
ping: function (conn, cb) {
ping: (conn, cb) => {
conn.query('SELECT 1', cb);
}
},
Expand All @@ -76,16 +76,16 @@ module.exports = {
client: 'postgresql',
connection: {
database: 'postgres',
user: 'postgres',
user: 'postgres',
password: 'Laik7akoh2ai',
host: process.env.DB_PORT_5432_TCP_ADDR,
port: process.env.DB_PORT_5432_TCP_PORT,
charset : 'utf8'
charset: 'utf8'
},
pool: {
min: 2,
max: 10,
ping: function (conn, cb) {
ping: (conn, cb) => {
conn.query('SELECT 1', cb);
}
},
Expand Down
92 changes: 45 additions & 47 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,58 +29,56 @@ import cors from 'kcors';
import serve from 'koa-static';
import bodyParser from 'koa-bodyparser';
import mount from 'koa-mount';
import knexLogger from 'knex-logger';
import chokidar from 'chokidar';
import ejs from 'ejs';
import { promisify } from 'bluebird';

import React from 'react';
import { renderToString } from 'react-dom/server'
import { createMemoryHistory } from 'history'
import { renderToString } from 'react-dom/server';
import { createMemoryHistory } from 'history';
import { Provider } from 'react-redux';
import { Router, RouterContext, match, useRouterHistory } from 'react-router'
import { Router, RouterContext, match, useRouterHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import Helmet from 'react-helmet';
import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';

import { getRoutes } from './src/routing';
import { AuthHandler, FetchHandler } from './src/utils/loader';
import {initApi} from './src/api/routing'
import { initApi } from './src/api/routing';
import initBookshelf from './src/api/db';
import initSphinx from './src/api/sphinx';
import { API_HOST } from './src/config';
import ApiClient from './src/api/client'
import ApiClient from './src/api/client';

import { initState } from './src/store';
import {
setCurrentUser, setLikes, setFavourites, setUserFollowedTags,
setUserFollowedSchools, setUserFollowedGeotags
setCurrentUser, setLikes, setFavourites
} from './src/actions';

import db_config from './knexfile';


let exec_env = process.env.DB_ENV || 'development';
const exec_env = process.env.DB_ENV || 'development';

let app = new Koa();
const app = new Koa();

let knexConfig = db_config[exec_env];
let bookshelf = initBookshelf(knexConfig);
let sphinx = initSphinx();
let api = initApi(bookshelf, sphinx);
let matchPromisified = promisify(match, { multiArgs: true });
let templatePath = path.join(__dirname, '/src/views/index.ejs');
let template = ejs.compile(fs.readFileSync(templatePath, 'utf8'), {filename: templatePath});
const knexConfig = db_config[exec_env];
const bookshelf = initBookshelf(knexConfig);
const sphinx = initSphinx();
const api = initApi(bookshelf, sphinx);
const matchPromisified = promisify(match, { multiArgs: true });
const templatePath = path.join(__dirname, '/src/views/index.ejs');
const template = ejs.compile(fs.readFileSync(templatePath, 'utf8'), { filename: templatePath });

if (exec_env === 'development') {
let webpackDevMiddleware = require('webpack-koa-dev-middleware').default;
let webpackHotMiddleware = require('webpack-koa-hot-middleware').default;
let webpack = require('webpack');
let webpackConfig = require('./webpack.dev.config');
let compiler = webpack(webpackConfig);
const webpackDevMiddleware = require('webpack-koa-dev-middleware').default;
const webpackHotMiddleware = require('webpack-koa-hot-middleware').default;
const webpack = require('webpack');
const webpackConfig = require('./webpack.dev.config');
const compiler = webpack(webpackConfig);

app.use(convert(webpackDevMiddleware(compiler, {
log: console.log,
log: console.log, // eslint-disable-line no-console
path: '/__webpack_hmr',
publicPath: webpackConfig.output.publicPath,
stats: {
Expand All @@ -94,10 +92,10 @@ if (exec_env === 'development') {
// Do "hot-reloading" of express stuff on the server
// Throw away cached modules and re-require next time
// Ensure there's no important state in there!
var watcher = chokidar.watch('./src/api');
const watcher = chokidar.watch('./src/api');
watcher.on('ready', function () {
watcher.on('all', function () {
console.log('Clearing /src/api/ cache from server');
console.log('Clearing /src/api/ cache from server'); // eslint-disable-line no-console
Object.keys(require.cache).forEach(function (id) {
if (/\/src\/api\//.test(id)) delete require.cache[id];
});
Expand All @@ -107,10 +105,10 @@ if (exec_env === 'development') {
// Do "hot-reloading" of react stuff on the server
// Throw away the cached client modules and let them be re-required next time
compiler.plugin('done', function () {
console.log('Clearing /src/ cache from server');
console.log('Clearing /src/ cache from server'); // eslint-disable-line no-console
Object.keys(require.cache).forEach(function (id) {
if (/\/src\//.test(id)) delete require.cache[id];
});
if (/\/src\//.test(id)) delete require.cache[id];
});
});
}

Expand All @@ -135,7 +133,7 @@ app.use(convert(session({
}
),
key: 'connect.sid',
cookie: {signed: false}
cookie: { signed: false }
})));

app.use(bodyParser()); // for parsing application/x-www-form-urlencoded
Expand All @@ -145,8 +143,8 @@ app.use(convert(cors({
})));

if (indexOf(['test', 'travis'], exec_env) !== -1) {
let warn = console.error; // eslint-disable-line no-console
console.error = function(warning) { // eslint-disable-line no-console
const warn = console.error; // eslint-disable-line no-console
console.error = function (warning) { // eslint-disable-line no-console
if (/(Invalid prop|Failed propType)/.test(warning)) {
throw new Error(warning);
}
Expand All @@ -158,14 +156,14 @@ app.use(mount('/api/v1', api));

app.use(convert(serve(`${__dirname}/public/`, { index: false, defer: false })));

app.use(async function reactMiddleware(ctx, next) {
app.use(async function reactMiddleware(ctx) {
const store = initState();

if (ctx.session && ctx.session.user && isString(ctx.session.user)) {
try {
let user = await bookshelf
const user = await bookshelf
.model('User')
.where({id: ctx.session.user})
.where({ id: ctx.session.user })
.fetch({
require: true,
withRelated: [
Expand All @@ -179,23 +177,23 @@ app.use(async function reactMiddleware(ctx, next) {
]
});

let data = user.toJSON();
const data = user.toJSON();

let likes = await bookshelf.knex
const likes = await bookshelf.knex
.select('post_id')
.from('likes')
.where({user_id: ctx.session.user});
.where({ user_id: ctx.session.user });

let favourites = await bookshelf.knex
const favourites = await bookshelf.knex
.select('post_id')
.from('favourites')
.where({user_id: ctx.session.user});
.where({ user_id: ctx.session.user });

store.dispatch(setCurrentUser(data));
store.dispatch(setLikes(data.id, likes.map(like => like.post_id)));
store.dispatch(setFavourites(data.id, favourites.map(fav => fav.post_id)));
} catch (e) {
console.log(`dispatch failed: ${e.stack}`);
console.log(`dispatch failed: ${e.stack}`); // eslint-disable-line no-console
}
}

Expand All @@ -211,10 +209,10 @@ app.use(async function reactMiddleware(ctx, next) {

const memoryHistory = useRouterHistory(createMemoryHistory)();
const history = syncHistoryWithStore(memoryHistory, store, { selectLocationState: state => state.get('routing') });
let routes = makeRoutes(history);
const routes = makeRoutes(history);

try {
const [ redirectLocation, renderProps ] = await matchPromisified({ routes, location: ctx.url });
const [redirectLocation, renderProps] = await matchPromisified({ routes, location: ctx.url });

if (redirectLocation) {
ctx.status = 307;
Expand All @@ -235,12 +233,12 @@ app.use(async function reactMiddleware(ctx, next) {
}

try {
let html = renderToString(
const html = renderToString(
<Provider store={store}>
<RouterContext {...renderProps}/>
</Provider>
);
let state = JSON.stringify(store.getState().toJS());
const state = JSON.stringify(store.getState().toJS());

if (fetchHandler.status !== null) {
ctx.status = fetchHandler.status;
Expand All @@ -249,14 +247,14 @@ app.use(async function reactMiddleware(ctx, next) {
const metadata = ExecutionEnvironment.canUseDOM ? Helmet.peek() : Helmet.rewind();

ctx.staus = 200;
ctx.body = template({state, html, metadata});
ctx.body = template({ state, html, metadata });
} catch (e) {
console.error(e.stack);
console.error(e.stack); // eslint-disable-line no-console
ctx.status = 500;
ctx.body = e.message;
}
} catch (e) {
console.error(e.stack);
console.error(e.stack); // eslint-disable-line no-console
ctx.status = 500;
ctx.body = e.message;
}
Expand Down
10 changes: 5 additions & 5 deletions tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const dbEnv = process.env.DB_ENV || 'development';
const knexConfig = dbConfig[dbEnv];
const bookshelf = initBookshelf(knexConfig);

let queue = kueLib.createQueue(config.kue);
const queue = kueLib.createQueue(config.kue);

queue.on('error', (err) => {
process.stderr.write(`${err.message}\n`);
Expand All @@ -41,7 +41,7 @@ queue.process('register-user-email', async function(job, done) {
hash } = job.data;

try {
let html = await renderVerificationTemplate(new Date(), username, email, `${API_URL_PREFIX}/user/verify/${hash}`);
const html = await renderVerificationTemplate(new Date(), username, email, `${API_URL_PREFIX}/user/verify/${hash}`);
await sendEmail('Please confirm email Libertysoil.org', html, job.data.email);
done();
} catch (e) {
Expand All @@ -51,7 +51,7 @@ queue.process('register-user-email', async function(job, done) {

queue.process('reset-password-email', async function(job, done) {
try {
let html = await renderResetTemplate(new Date(), job.data.username, job.data.email, `${API_HOST}/newpassword/${job.data.hash}`);
const html = await renderResetTemplate(new Date(), job.data.username, job.data.email, `${API_HOST}/newpassword/${job.data.hash}`);
await sendEmail('Reset Libertysoil.org Password', html, job.data.email);
done();
} catch (e) {
Expand All @@ -73,7 +73,7 @@ queue.process('on-comment', async function(job, done) {
try {
const Comment = bookshelf.model('Comment');

const comment = await Comment.where({id: job.data.commentId}).fetch({require: true, withRelated: ['user', 'post', 'post.user']});
const comment = await Comment.where({ id: job.data.commentId }).fetch({ require: true, withRelated: ['user', 'post', 'post.user'] });
const commentAuthor = comment.related('user');
const post = comment.related('post');
const postAuthor = comment.related('post').related('user');
Expand All @@ -82,7 +82,7 @@ queue.process('on-comment', async function(job, done) {
queue.create('new-comment-email', {
comment: comment.attributes,
commentAuthor: commentAuthor.attributes,
post: post.attributes,
post: post.attributes,
postAuthor: postAuthor.attributes
}).save();
}
Expand Down
Loading

0 comments on commit b54018a

Please sign in to comment.