setup and run prettier
This commit is contained in:
parent
c4bb4c9c02
commit
3a3072681d
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/build
|
||||||
|
/dump
|
||||||
22
.eslintrc
Normal file
22
.eslintrc
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
|
||||||
|
"settings": {
|
||||||
|
"import/resolver": {
|
||||||
|
"node": {
|
||||||
|
"extensions": [".js", ".jsx", ".mjs"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"extends": ["standard", "prettier"],
|
||||||
|
|
||||||
|
"rules": {
|
||||||
|
"import/no-extraneous-dependencies": 2,
|
||||||
|
"no-console": [2, { "allow": ["info", "error", "warn"] }],
|
||||||
|
"no-unused-expressions": 0,
|
||||||
|
"no-unused-vars": 0,
|
||||||
|
"no-var": 2,
|
||||||
|
"prefer-const": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,6 +20,6 @@ div.item.gu-mirror {
|
|||||||
.gu-transit {
|
.gu-transit {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
opacity: 0.2;
|
opacity: 0.2;
|
||||||
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)";
|
-ms-filter: 'progid:DXImageTransform.Microsoft.Alpha(Opacity=20)';
|
||||||
filter: alpha(opacity=20);
|
filter: alpha(opacity=20);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
@import "./dragula";
|
@import './dragula';
|
||||||
|
|
||||||
div.container {
|
div.container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
7
client/.eslintrc
Normal file
7
client/.eslintrc
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": ["../.eslintrc", "standard-jsx", "prettier/react"],
|
||||||
|
|
||||||
|
"env": {
|
||||||
|
"browser": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,51 +1,52 @@
|
|||||||
import { pick } from 'lowline';
|
import { pick } from 'lowline'
|
||||||
|
|
||||||
export const DELETE_RESULT = 'DELETE_RESULT';
|
export const DELETE_RESULT = 'DELETE_RESULT'
|
||||||
|
|
||||||
const baseUrl = '/api/results';
|
const baseUrl = '/api/results'
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
accept: 'application/json',
|
accept: 'application/json',
|
||||||
};
|
}
|
||||||
|
|
||||||
export const FETCH_RESULTS = 'FETCH_RESULTS';
|
export const FETCH_RESULTS = 'FETCH_RESULTS'
|
||||||
|
|
||||||
// query can be a query string (without ?, ie not a search string)
|
// query can be a query string (without ?, ie not a search string)
|
||||||
export function fetchResults(query = {}) {
|
export function fetchResults(query = {}) {
|
||||||
query = typeof query === 'string' ? query : qs.stringify(query);
|
query = typeof query === 'string' ? query : qs.stringify(query)
|
||||||
|
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
fetch(`${baseUrl}${query ? `?${query}` : ''}`, {
|
fetch(`${baseUrl}${query ? `?${query}` : ''}`, {
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
headers,
|
headers,
|
||||||
}).then((res) => res.json())
|
})
|
||||||
|
.then((res) => res.json())
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
const actions = [receiveResults(json.results || [])];
|
const actions = [receiveResults(json.results || [])]
|
||||||
|
|
||||||
if (json.perPage) {
|
if (json.perPage) {
|
||||||
actions.push(setPagination(pick(json, 'perPage', 'totalCount')));
|
actions.push(setPagination(pick(json, 'perPage', 'totalCount')))
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(batchActions(actions));
|
dispatch(batchActions(actions))
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RECEIVE_RESULTS = 'RECEIVE_RESULTS';
|
export const RECEIVE_RESULTS = 'RECEIVE_RESULTS'
|
||||||
|
|
||||||
export function receiveResults(json) {
|
export function receiveResults(json) {
|
||||||
return {
|
return {
|
||||||
type: RECEIVE_RESULTS,
|
type: RECEIVE_RESULTS,
|
||||||
payload: json,
|
payload: json,
|
||||||
receivedAt: Date.now(),
|
receivedAt: Date.now(),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const REMOVE_RESULTS = 'REMOVE_RESULTS';
|
export const REMOVE_RESULTS = 'REMOVE_RESULTS'
|
||||||
|
|
||||||
export function removeResults() {
|
export function removeResults() {
|
||||||
return {
|
return {
|
||||||
type: REMOVE_RESULTS,
|
type: REMOVE_RESULTS,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
import { h } from 'preact';
|
import { h } from 'preact'
|
||||||
|
|
||||||
import formatTime from '../util/formatTime';
|
import formatTime from '../util/formatTime'
|
||||||
|
|
||||||
export default (props) => (
|
export default (props) => (
|
||||||
<li>
|
<li>
|
||||||
<span class="line">{props.Line.Name}</span>
|
<span class='line'>{props.Line.Name}</span>
|
||||||
<ul>
|
<ul>
|
||||||
<li>{formatTime(props.DepDateTime)} {props.From.Name}</li>
|
<li>
|
||||||
<li>{formatTime(props.ArrDateTime)} {props.To.Name}</li>
|
{formatTime(props.DepDateTime)} {props.From.Name}
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
{formatTime(props.ArrDateTime)} {props.To.Name}
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
);
|
)
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact'
|
||||||
|
|
||||||
import Link from './Link';
|
import Link from './Link'
|
||||||
|
|
||||||
import formatTime from '../util/formatTime';
|
import formatTime from '../util/formatTime'
|
||||||
|
|
||||||
export default class Result extends Component {
|
export default class Result extends Component {
|
||||||
toggle() {
|
toggle() {
|
||||||
console.log('toggle');
|
console.log('toggle')
|
||||||
this.setState({
|
this.setState({
|
||||||
expand: !this.state.expand,
|
expand: !this.state.expand,
|
||||||
})
|
})
|
||||||
@ -17,9 +17,11 @@ export default class Result extends Component {
|
|||||||
<li className={{ expand }} onClick={() => this.toggle()}>
|
<li className={{ expand }} onClick={() => this.toggle()}>
|
||||||
{formatTime(props.DepDateTime)} - {formatTime(props.ArrDateTime)}
|
{formatTime(props.DepDateTime)} - {formatTime(props.ArrDateTime)}
|
||||||
<ul>
|
<ul>
|
||||||
{props.RouteLinks.RouteLink.map((link, i) => <Link key={i} {...link} />)}
|
{props.RouteLinks.RouteLink.map((link, i) => (
|
||||||
|
<Link key={i} {...link} />
|
||||||
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,24 +1,21 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact'
|
||||||
|
|
||||||
import Result from './Result';
|
import Result from './Result'
|
||||||
import store from '../store';
|
import store from '../store'
|
||||||
|
|
||||||
export default class ResultList extends Component {
|
export default class ResultList extends Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.unsubscribe = store.subscribe(() => this.forceUpdate());
|
this.unsubscribe = store.subscribe(() => this.forceUpdate())
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.unsubscribe();
|
this.unsubscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { results } = store.getState();
|
const { results } = store.getState()
|
||||||
console.log(results);
|
console.log(results)
|
||||||
|
|
||||||
return (
|
return <ul>{results && results.map((result, i) => <Result key={i} {...result} />)}</ul>
|
||||||
<ul>{results && results.map((result, i) => <Result key={i} {...result} />)}</ul>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import { $, $$ } from 'dollr';
|
import { $, $$ } from 'dollr'
|
||||||
import dragula from 'dragula';
|
import dragula from 'dragula'
|
||||||
|
|
||||||
import { h, render } from 'preact';
|
import { h, render } from 'preact'
|
||||||
import ResultList from './components/ResultList';
|
import ResultList from './components/ResultList'
|
||||||
|
|
||||||
import store from './store';
|
import store from './store'
|
||||||
import { receiveResults } from './actions/results';
|
import { receiveResults } from './actions/results'
|
||||||
const result = $('pre');
|
const result = $('pre')
|
||||||
const containers = $$('.location');
|
const containers = $$('.location')
|
||||||
|
|
||||||
const drake = dragula(containers, {
|
const drake = dragula(containers, {
|
||||||
revertOnSpill: true,
|
revertOnSpill: true,
|
||||||
@ -18,10 +18,10 @@ const drake = dragula(containers, {
|
|||||||
|
|
||||||
ignoreInputTextSelection: false,
|
ignoreInputTextSelection: false,
|
||||||
// }
|
// }
|
||||||
});
|
})
|
||||||
|
|
||||||
drake.on('drop', (el, target, source) => {
|
drake.on('drop', (el, target, source) => {
|
||||||
drake.cancel();
|
drake.cancel()
|
||||||
|
|
||||||
if (target !== source) {
|
if (target !== source) {
|
||||||
fetch('/api/trip', {
|
fetch('/api/trip', {
|
||||||
@ -34,37 +34,36 @@ drake.on('drop', (el, target, source) => {
|
|||||||
from: source.dataset.location,
|
from: source.dataset.location,
|
||||||
to: target.dataset.location,
|
to: target.dataset.location,
|
||||||
}),
|
}),
|
||||||
}).then((res) => {
|
})
|
||||||
return res.json();
|
.then((res) => {
|
||||||
}).then((json) => {
|
return res.json()
|
||||||
console.log(json);
|
})
|
||||||
|
.then((json) => {
|
||||||
|
console.log(json)
|
||||||
// result.textContent = JSON.stringify(json, null, ' ')
|
// result.textContent = JSON.stringify(json, null, ' ')
|
||||||
store.dispatch(receiveResults(json));
|
store.dispatch(receiveResults(json))
|
||||||
}).catch((err) => {
|
})
|
||||||
console.log('error');
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log('error')
|
||||||
});
|
console.log(err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
function prevent(e) {
|
function prevent(e) {
|
||||||
e.preventDefault();
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
drake.on('over', (el, target, source) => {
|
drake.on('over', (el, target, source) => {
|
||||||
if (target !== source) {
|
if (target !== source) {
|
||||||
target.classList.add('over');
|
target.classList.add('over')
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
drake.on('out', (el, target, source) => {
|
drake.on('out', (el, target, source) => {
|
||||||
if (target !== source) {
|
if (target !== source) {
|
||||||
target.classList.remove('over');
|
target.classList.remove('over')
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
render(
|
|
||||||
<ResultList />,
|
|
||||||
$('#results')
|
|
||||||
);
|
|
||||||
|
|
||||||
|
render(<ResultList />, $('#results'))
|
||||||
|
|||||||
@ -1,26 +1,44 @@
|
|||||||
import { h } from 'jsx-node';
|
import { h } from 'jsx-node'
|
||||||
|
|
||||||
export default ({ articleUrl, protocol, hostname, websocketsPort, INITIAL_STATE, js, css, cssFile }) => {
|
export default ({ articleUrl, protocol, hostname, websocketsPort, INITIAL_STATE, js, css, cssFile }) => {
|
||||||
return '<!doctype html>' + (
|
return (
|
||||||
|
'<!doctype html>' +
|
||||||
|
(
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Journey</title>
|
<title>Journey</title>
|
||||||
<meta charset="UTF-8" />
|
<meta charset='UTF-8' />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
|
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' />
|
||||||
<link type="text/css" rel="stylesheet" href={`/css/main` + (css ? css.suffix : '') + '.css'} />
|
<link type='text/css' rel='stylesheet' href={`/css/main` + (css ? css.suffix : '') + '.css'} />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div class='container'>
|
||||||
<div class="container">
|
<div data-location='home' class='location l01'>
|
||||||
<div data-location="home" class="location l01"><div data-location="home" class="item"><span>Home</span></div></div>
|
<div data-location='home' class='item'>
|
||||||
<div data-location="office" class="location l02"><div data-location="office" class="item"><span>Office</span></div></div>
|
<span>Home</span>
|
||||||
<div data-location="brother" class="location l03"><div data-location="brother" class="item"><span>Brother</span></div></div>
|
|
||||||
<div data-location="therapist" class="location l04"><div data-location="therapist" class="item"><span>The Rapist</span></div></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="results"></div>
|
</div>
|
||||||
<script src={"/js/app" + (js ? js.suffix : '') + '.js'} />
|
<div data-location='office' class='location l02'>
|
||||||
|
<div data-location='office' class='item'>
|
||||||
|
<span>Office</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div data-location='brother' class='location l03'>
|
||||||
|
<div data-location='brother' class='item'>
|
||||||
|
<span>Brother</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div data-location='therapist' class='location l04'>
|
||||||
|
<div data-location='therapist' class='item'>
|
||||||
|
<span>The Rapist</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id='results' />
|
||||||
|
<script src={'/js/app' + (js ? js.suffix : '') + '.js'} />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
)
|
||||||
};
|
)
|
||||||
|
}
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import { h } from 'jsx-node';
|
import { h } from 'jsx-node'
|
||||||
|
|
||||||
export default ({ error = {}, regions = {}}) => (
|
export default ({ error = {}, regions = {} }) => (
|
||||||
<section className="error page">
|
<section className='error page'>
|
||||||
<h1>Oops!</h1>
|
<h1>Oops!</h1>
|
||||||
<p>Ett problem har tyvärr uppstått.</p>
|
<p>Ett problem har tyvärr uppstått.</p>
|
||||||
<h2>{error.status} {error.statusText}</h2>
|
<h2>
|
||||||
|
{error.status} {error.statusText}
|
||||||
|
</h2>
|
||||||
<p>{error.message}</p>
|
<p>{error.message}</p>
|
||||||
</section>
|
</section>
|
||||||
);
|
)
|
||||||
|
|||||||
@ -1,16 +1,12 @@
|
|||||||
import {
|
import { RECEIVE_RESULTS, REMOVE_RESULTS } from '../actions/results'
|
||||||
RECEIVE_RESULTS,
|
|
||||||
REMOVE_RESULTS,
|
|
||||||
} from '../actions/results';
|
|
||||||
|
|
||||||
export default (state = null, action) => {
|
export default (state = null, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case RECEIVE_RESULTS:
|
case RECEIVE_RESULTS:
|
||||||
return action.payload || [];
|
return action.payload || []
|
||||||
case REMOVE_RESULTS:
|
case REMOVE_RESULTS:
|
||||||
return null;
|
return null
|
||||||
default:
|
default:
|
||||||
return state;
|
return state
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { combineReducers } from 'redux';
|
import { combineReducers } from 'redux'
|
||||||
|
|
||||||
import results from './results';
|
import results from './results'
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
results,
|
results,
|
||||||
});
|
})
|
||||||
|
|||||||
@ -1,15 +1,9 @@
|
|||||||
import thunkMiddleware from 'redux-thunk';
|
import thunkMiddleware from 'redux-thunk'
|
||||||
import createLogger from 'redux-logger';
|
import createLogger from 'redux-logger'
|
||||||
import { createStore, applyMiddleware } from 'redux';
|
import { createStore, applyMiddleware } from 'redux'
|
||||||
|
|
||||||
const loggerMiddleware = createLogger();
|
import rootReducer from './reducers/root'
|
||||||
|
|
||||||
import rootReducer from './reducers/root';
|
const loggerMiddleware = createLogger()
|
||||||
|
|
||||||
export default createStore(
|
export default createStore(rootReducer, applyMiddleware(thunkMiddleware, loggerMiddleware))
|
||||||
rootReducer,
|
|
||||||
applyMiddleware(
|
|
||||||
thunkMiddleware,
|
|
||||||
loggerMiddleware
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export default function formatDateTime(str) {
|
export default function formatDateTime(str) {
|
||||||
return str.split('T')[1].slice(0, -3);
|
return str.split('T')[1].slice(0, -3)
|
||||||
}
|
}
|
||||||
|
|||||||
19
package.json
19
package.json
@ -4,6 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "server/server.js",
|
"main": "server/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"lint": "eslint --ext .js --ext .jsx --ext .mjs .",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "Linus Miller <lohfu@lohfu.io> (https://lohfu.io/)",
|
"author": "Linus Miller <lohfu@lohfu.io> (https://lohfu.io/)",
|
||||||
@ -36,11 +38,16 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"app-module-path": "^1.1.0",
|
"app-module-path": "^1.1.0",
|
||||||
"eslint": "^3.15.0",
|
"eslint": "^7.4.0",
|
||||||
"eslint-config-airbnb": "^14.1.0",
|
"eslint-config-prettier": "^6.11.0",
|
||||||
"eslint-config-airbnb-base": "^11.1.0",
|
"eslint-config-standard": "^14.1.1",
|
||||||
"eslint-plugin-import": "^2.2.0",
|
"eslint-config-standard-react": "^9.2.0",
|
||||||
"eslint-plugin-jsx-a11y": "^4.0.0",
|
"eslint-import-resolver-typescript": "^2.0.0",
|
||||||
"eslint-plugin-react": "^6.9.0"
|
"eslint-plugin-import": "^2.22.0",
|
||||||
|
"eslint-plugin-node": "^11.1.0",
|
||||||
|
"eslint-plugin-promise": "^4.2.1",
|
||||||
|
"eslint-plugin-react": "^7.20.3",
|
||||||
|
"eslint-plugin-standard": "^4.0.1",
|
||||||
|
"prettier": "^2.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
prettier.config.js
Normal file
18
prettier.config.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
jsxSingleQuote: true,
|
||||||
|
printWidth: 120,
|
||||||
|
semi: false,
|
||||||
|
singleQuote: true,
|
||||||
|
trailingComma: 'all',
|
||||||
|
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: '*.scss',
|
||||||
|
options: {
|
||||||
|
trailingComma: 'none',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
7
server/.eslintrc
Normal file
7
server/.eslintrc
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": ["../.eslintrc"],
|
||||||
|
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const p = require('path');
|
const p = require('path')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
static: p.join(PWD, 'public'),
|
static: p.join(PWD, 'public'),
|
||||||
};
|
}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash')
|
||||||
|
|
||||||
const errorTemplate = require('../../build/pages/Error');
|
const errorTemplate = require('../../build/pages/Error')
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
post: (req, res, next) => {
|
post: (req, res, next) => {
|
||||||
res.template = errorTemplate;
|
res.template = errorTemplate
|
||||||
|
|
||||||
next();
|
next()
|
||||||
},
|
},
|
||||||
|
|
||||||
mystify: {
|
mystify: {
|
||||||
@ -19,11 +19,13 @@ const defaults = {
|
|||||||
// if database = true there has to be a mongoose model name ErrorModel
|
// if database = true there has to be a mongoose model name ErrorModel
|
||||||
ignore: [],
|
ignore: [],
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
|
|
||||||
const store = require('midwest-service-errors/stores/postgres');
|
const store = require('midwest-service-errors/stores/postgres')
|
||||||
|
|
||||||
module.exports = _.merge(defaults, {
|
module.exports = _.merge(
|
||||||
|
defaults,
|
||||||
|
{
|
||||||
development: {
|
development: {
|
||||||
log: {
|
log: {
|
||||||
store,
|
store,
|
||||||
@ -48,4 +50,5 @@ module.exports = _.merge(defaults, {
|
|||||||
console: false,
|
console: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}[ENV]);
|
}[ENV],
|
||||||
|
)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
// global.LOGIN_USER = 'linus.miller@bitmill.co';
|
// global.LOGIN_USER = 'linus.miller@bitmill.co';
|
||||||
// global.LOGIN_USER = 'zarac@zarac.se';
|
// global.LOGIN_USER = 'zarac@zarac.se';
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash')
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
site: require('./site'),
|
site: require('./site'),
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
invite: {
|
invite: {
|
||||||
@ -52,7 +52,7 @@ module.exports = {
|
|||||||
noUserFound: 'No user registered with that email.',
|
noUserFound: 'No user registered with that email.',
|
||||||
noExternalUser: 'The account is not connected to this website.',
|
noExternalUser: 'The account is not connected to this website.',
|
||||||
externalLoginFailed: 'External login failed.',
|
externalLoginFailed: 'External login failed.',
|
||||||
emailNotVerified: 'This account\'s email has not been verified.',
|
emailNotVerified: "This account's email has not been verified.",
|
||||||
banned: 'User is banned.',
|
banned: 'User is banned.',
|
||||||
blocked: 'User is blocked due to too many login attempts.',
|
blocked: 'User is blocked due to too many login attempts.',
|
||||||
},
|
},
|
||||||
@ -71,14 +71,13 @@ module.exports = {
|
|||||||
|
|
||||||
scope: ['email'],
|
scope: ['email'],
|
||||||
|
|
||||||
//providers: {
|
// providers: {
|
||||||
// facebook: {
|
// facebook: {
|
||||||
// clientID: 'change-this-fool',
|
// clientID: 'change-this-fool',
|
||||||
// clientSecret: 'change-this-fool',
|
// clientSecret: 'change-this-fool',
|
||||||
// callbackURL: p.join(config.site.domain, '/auth/facebook/callback'),
|
// callbackURL: p.join(config.site.domain, '/auth/facebook/callback'),
|
||||||
// passReqToCallback: true
|
// passReqToCallback: true
|
||||||
// },
|
// },
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
userColumns: [
|
userColumns: [
|
||||||
@ -89,18 +88,21 @@ module.exports = {
|
|||||||
'dateMuted',
|
'dateMuted',
|
||||||
'dateVerified',
|
'dateVerified',
|
||||||
// ['array(SELECT name FROM user_roles LEFT OUTER JOIN roles ON user_roles.role_id = roles.id WHERE user_roles.user_id = users.id)', 'roles'],
|
// ['array(SELECT name FROM user_roles LEFT OUTER JOIN roles ON user_roles.role_id = roles.id WHERE user_roles.user_id = users.id)', 'roles'],
|
||||||
[`(SELECT array_to_json(array_agg(row_to_json(d)))
|
[
|
||||||
|
`(SELECT array_to_json(array_agg(row_to_json(d)))
|
||||||
FROM (
|
FROM (
|
||||||
SELECT id, name
|
SELECT id, name
|
||||||
FROM user_roles
|
FROM user_roles
|
||||||
LEFT OUTER JOIN roles ON user_roles.role_id = roles.id WHERE user_roles.user_id = users.id
|
LEFT OUTER JOIN roles ON user_roles.role_id = roles.id WHERE user_roles.user_id = users.id
|
||||||
ORDER BY roles.id DESC
|
ORDER BY roles.id DESC
|
||||||
) d
|
) d
|
||||||
)`, 'roles'],
|
)`,
|
||||||
|
'roles',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
// needs to be even
|
// needs to be even
|
||||||
tokenLength: 64,
|
tokenLength: 64,
|
||||||
// needs to be even
|
// needs to be even
|
||||||
saltLength: 16,
|
saltLength: 16,
|
||||||
};
|
}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const basePort = 3060;
|
const basePort = 3060
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
development: basePort,
|
development: basePort,
|
||||||
testing: basePort + 1,
|
testing: basePort + 1,
|
||||||
staging: basePort + 2,
|
staging: basePort + 2,
|
||||||
production: basePort + 3,
|
production: basePort + 3,
|
||||||
}[ENV];
|
}[ENV]
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
user: 'newseri_supreme', // env var: PGUSER
|
user: 'newseri_supreme', // env var: PGUSER
|
||||||
@ -10,7 +10,6 @@ const defaults = {
|
|||||||
port: 6543, // env var: PGPORT
|
port: 6543, // env var: PGPORT
|
||||||
max: 10, // max number of clients in the pool
|
max: 10, // max number of clients in the pool
|
||||||
idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
|
idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = Object.assign(defaults, {
|
module.exports = Object.assign(defaults, {}[ENV])
|
||||||
}[ENV]);
|
|
||||||
|
|||||||
@ -1,38 +1,38 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk')
|
||||||
const session = require('express-session');
|
const session = require('express-session')
|
||||||
|
|
||||||
let redisStore;
|
let redisStore
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
secret: 'asdfpoi7u987777777777777777777sdkafjxxjasdhfhsadfhashdfh`1111111khjjashdfkasjhdflGGGGGGGGGGaaa^^^^^^^^^^yaghsdfqw3u7679`',
|
secret:
|
||||||
|
'asdfpoi7u987777777777777777777sdkafjxxjasdhfhsadfhashdfh`1111111khjjashdfkasjhdflGGGGGGGGGGaaa^^^^^^^^^^yaghsdfqw3u7679`',
|
||||||
resave: false,
|
resave: false,
|
||||||
saveUninitialized: true,
|
saveUninitialized: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
const redisConfig = {
|
const redisConfig = {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 6379,
|
port: 6379,
|
||||||
};
|
|
||||||
|
|
||||||
if (ENV === 'production') {
|
|
||||||
const RedisStore = require('connect-redis')(require('express-session'));
|
|
||||||
|
|
||||||
redisStore = new RedisStore(redisConfig);
|
|
||||||
|
|
||||||
redisStore.on('connect', () => {
|
|
||||||
console.info(`[${chalk.cyan('INIT')}] Redis connected succcessfully`);
|
|
||||||
});
|
|
||||||
|
|
||||||
redisStore.on('disconnect', () => {
|
|
||||||
throw new Error('Unable to connect to redis. Has it been started?');
|
|
||||||
});
|
|
||||||
|
|
||||||
config.store = redisStore;
|
|
||||||
} else {
|
|
||||||
config.store = new session.MemoryStore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = config;
|
if (ENV === 'production') {
|
||||||
|
const RedisStore = require('connect-redis')(require('express-session'))
|
||||||
|
|
||||||
|
redisStore = new RedisStore(redisConfig)
|
||||||
|
|
||||||
|
redisStore.on('connect', () => {
|
||||||
|
console.info(`[${chalk.cyan('INIT')}] Redis connected succcessfully`)
|
||||||
|
})
|
||||||
|
|
||||||
|
redisStore.on('disconnect', () => {
|
||||||
|
throw new Error('Unable to connect to redis. Has it been started?')
|
||||||
|
})
|
||||||
|
|
||||||
|
config.store = redisStore
|
||||||
|
} else {
|
||||||
|
config.store = new session.MemoryStore()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = config
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.min.js': [
|
'https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.min.js': [
|
||||||
@ -31,4 +31,4 @@ module.exports = {
|
|||||||
'ie <= 11',
|
'ie <= 11',
|
||||||
'safari <= 9',
|
'safari <= 9',
|
||||||
],
|
],
|
||||||
};
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash')
|
||||||
|
|
||||||
const domain = 'newseri.com';
|
const domain = 'newseri.com'
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
domain,
|
domain,
|
||||||
@ -10,10 +10,10 @@ const defaults = {
|
|||||||
name: 'newseri-admin',
|
name: 'newseri-admin',
|
||||||
protocol: 'http',
|
protocol: 'http',
|
||||||
get host() {
|
get host() {
|
||||||
return this.port ? this.hostname + ':' + this.port : this.hostname;
|
return this.port ? this.hostname + ':' + this.port : this.hostname
|
||||||
},
|
},
|
||||||
get url() {
|
get url() {
|
||||||
return this.protocol + '://' + this.host + '/';
|
return this.protocol + '://' + this.host + '/'
|
||||||
},
|
},
|
||||||
emails: {
|
emails: {
|
||||||
robot: 'no-reply@thecodebureau.com',
|
robot: 'no-reply@thecodebureau.com',
|
||||||
@ -21,9 +21,11 @@ const defaults = {
|
|||||||
webmaster: 'webmaster@thecodebureau.com',
|
webmaster: 'webmaster@thecodebureau.com',
|
||||||
order: 'info@thecodebureau.com',
|
order: 'info@thecodebureau.com',
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = _.merge(defaults, {
|
module.exports = _.merge(
|
||||||
|
defaults,
|
||||||
|
{
|
||||||
development: {
|
development: {
|
||||||
hostname: 'localhost',
|
hostname: 'localhost',
|
||||||
port: process.env.EXTERNAL_PORT || process.env.PORT || require('./port'),
|
port: process.env.EXTERNAL_PORT || process.env.PORT || require('./port'),
|
||||||
@ -48,4 +50,5 @@ module.exports = _.merge(defaults, {
|
|||||||
// order: 'order@' + domain,
|
// order: 'order@' + domain,
|
||||||
// },
|
// },
|
||||||
},
|
},
|
||||||
}[ENV]);
|
}[ENV],
|
||||||
|
)
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash')
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
auth: {
|
auth: {
|
||||||
@ -10,6 +10,6 @@ const defaults = {
|
|||||||
},
|
},
|
||||||
host: 'smtp.sparkpostmail.com',
|
host: 'smtp.sparkpostmail.com',
|
||||||
port: 587,
|
port: 587,
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = _.merge(defaults, {}[ENV]);
|
module.exports = _.merge(defaults, {}[ENV])
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const factory = require('midwest/util/db');
|
const factory = require('midwest/util/db')
|
||||||
const conf = require('./config/postgres');
|
const conf = require('./config/postgres')
|
||||||
|
|
||||||
module.exports = factory(conf);
|
module.exports = factory(conf)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
// const requireDir = require('require-dir');
|
// const requireDir = require('require-dir');
|
||||||
// const membership = require('midwest-module-membership');
|
// const membership = require('midwest-module-membership');
|
||||||
@ -6,5 +6,4 @@
|
|||||||
// const config = requireDir('./config', { camelcase: true });
|
// const config = requireDir('./config', { camelcase: true });
|
||||||
// const db = require('./db');
|
// const db = require('./db');
|
||||||
|
|
||||||
|
|
||||||
// membership.configure(Object.assign({ db, site: config.site, smtp: config.smtp }, config.membership));
|
// membership.configure(Object.assign({ db, site: config.site, smtp: config.smtp }, config.membership));
|
||||||
|
|||||||
@ -1,32 +1,28 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const { h } = require('jsx-node');
|
const { h } = require('jsx-node')
|
||||||
|
|
||||||
module.exports = function (Component, Master) {
|
module.exports = function (Component, Master) {
|
||||||
const locals = Object.assign({ query: this.req.query }, this.app.locals, this.locals);
|
const locals = Object.assign({ query: this.req.query }, this.app.locals, this.locals)
|
||||||
|
|
||||||
let html;
|
let html
|
||||||
|
|
||||||
if (typeof Master === 'function') {
|
if (typeof Master === 'function') {
|
||||||
if (typeof Component === 'function') {
|
if (typeof Component === 'function') {
|
||||||
return this.send(
|
return this.send(h(Master, locals, h(Component, locals)))
|
||||||
h(Master, locals,
|
|
||||||
h(Component, locals)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component = Master;
|
Component = Master
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof Component !== 'function') {
|
if (typeof Component !== 'function') {
|
||||||
throw new Error('Not a Component');
|
throw new Error('Not a Component')
|
||||||
} else if (Component.prototype && Component.prototype.render) {
|
} else if (Component.prototype && Component.prototype.render) {
|
||||||
const i = new Component(locals);
|
const i = new Component(locals)
|
||||||
html = i.render(i.props, i.state);
|
html = i.render(i.props, i.state)
|
||||||
} else {
|
} else {
|
||||||
html = Component(locals);
|
html = Component(locals)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send(html);
|
this.send(html)
|
||||||
};
|
}
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
|
const format = require('easy-tz/cjs/format')
|
||||||
|
|
||||||
const format = require('easy-tz/cjs/format');
|
const request = require('superagent')
|
||||||
|
|
||||||
const request = require('superagent');
|
|
||||||
|
|
||||||
// import get from 'get-value';
|
// import get from 'get-value';
|
||||||
const _ = require('lodash');
|
const _ = require('lodash')
|
||||||
|
|
||||||
const xml2json = require('xml2json');
|
const xml2json = require('xml2json')
|
||||||
|
|
||||||
// const to = 'Lund Mellanvångsvägen';
|
// const to = 'Lund Mellanvångsvägen';
|
||||||
// const from = 'Malmö Triangeln';
|
// const from = 'Malmö Triangeln';
|
||||||
@ -40,47 +39,49 @@ const stations = {
|
|||||||
name: 'Malmö Triangeln',
|
name: 'Malmö Triangeln',
|
||||||
type: 'STOP_AREA',
|
type: 'STOP_AREA',
|
||||||
},
|
},
|
||||||
};
|
|
||||||
|
|
||||||
const types = {
|
|
||||||
'STOP_AREA': 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const router = new (require('express')).Router();
|
const types = {
|
||||||
|
STOP_AREA: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
const router = new (require('express').Router)()
|
||||||
|
|
||||||
function formatStation(json) {
|
function formatStation(json) {
|
||||||
return `${encodeURIComponent(json.name)}|${json.id}|${types[json.type]}`
|
return `${encodeURIComponent(json.name)}|${json.id}|${types[json.type]}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatTime(date) {
|
function formatTime(date) {
|
||||||
date = date || new Date();
|
date = date || new Date()
|
||||||
|
|
||||||
return format(null, 'YYYY-MM-DD HH:mm', date);
|
|
||||||
|
|
||||||
|
|
||||||
|
return format(null, 'YYYY-MM-DD HH:mm', date)
|
||||||
}
|
}
|
||||||
console.log(formatTime());
|
console.log(formatTime())
|
||||||
|
|
||||||
function formatLink(link) {
|
function formatLink(link) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatResult(result) {
|
function formatResult(result) {
|
||||||
return _.omit(result, 'Prices');
|
return _.omit(result, 'Prices')
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(new Date('2017-02-24T17:16:00'.split('T').join(' ')).toLocaleString());
|
console.log(new Date('2017-02-24T17:16:00'.split('T').join(' ')).toLocaleString())
|
||||||
|
|
||||||
const journeysPath = [ 'soap:Envelope', 'soap:Body', 'GetJourneyResponse', 'GetJourneyResult', 'Journeys', 'Journey']
|
const journeysPath = ['soap:Envelope', 'soap:Body', 'GetJourneyResponse', 'GetJourneyResult', 'Journeys', 'Journey']
|
||||||
// http://www.labs.skanetrafiken.se/v2.2/resultspage.asp?cmdaction=next&selPointFr=malm%F6%20C|80000|0&selPointTo=landskrona|82000|0&LastStart=2017-02-23%2016:38
|
// http://www.labs.skanetrafiken.se/v2.2/resultspage.asp?cmdaction=next&selPointFr=malm%F6%20C|80000|0&selPointTo=landskrona|82000|0&LastStart=2017-02-23%2016:38
|
||||||
router.post('/trip', (req, res, next) => {
|
router.post('/trip', (req, res, next) => {
|
||||||
request(`http://www.labs.skanetrafiken.se/v2.2/resultspage.asp?cmdaction=next&selPointFr=${formatStation(stations[req.body.from])}&selPointTo=${formatStation(stations[req.body.to])}&LastStart=${encodeURIComponent(formatTime(req.body.datetime))}`).then((response) =>{
|
request(
|
||||||
const result = _.get(xml2json.toJson(response.text, { object: true }), journeysPath);
|
`http://www.labs.skanetrafiken.se/v2.2/resultspage.asp?cmdaction=next&selPointFr=${formatStation(
|
||||||
|
stations[req.body.from],
|
||||||
|
)}&selPointTo=${formatStation(stations[req.body.to])}&LastStart=${encodeURIComponent(
|
||||||
|
formatTime(req.body.datetime),
|
||||||
|
)}`,
|
||||||
|
).then((response) => {
|
||||||
|
const result = _.get(xml2json.toJson(response.text, { object: true }), journeysPath)
|
||||||
|
|
||||||
result.forEach(formatResult);
|
result.forEach(formatResult)
|
||||||
|
|
||||||
res.json(result);
|
res.json(result)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
// const masterTemplate = require('../client/public/components/Master');
|
// const masterTemplate = require('../client/public/components/Master');
|
||||||
const masterTemplate = require('../../build/master');
|
const masterTemplate = require('../../build/master')
|
||||||
// const loginFormTemplate = require('../build/components/login-form/template');
|
// const loginFormTemplate = require('../build/components/login-form/template');
|
||||||
// const registerFormTemplate = require('../build/components/register-form/template');
|
// const registerFormTemplate = require('../build/components/register-form/template');
|
||||||
// const changePasswordFormTemplate = require('../build/components/change-password-form/template');
|
// const changePasswordFormTemplate = require('../build/components/change-password-form/template');
|
||||||
// const forgotPasswordFormTemplate = require('../build/components/forgot-password-form/template');
|
// const forgotPasswordFormTemplate = require('../build/components/forgot-password-form/template');
|
||||||
// const bareMasterTemplate = require('../build/bare-master');
|
// const bareMasterTemplate = require('../build/bare-master');
|
||||||
|
|
||||||
const router = new (require('express')).Router();
|
const router = new (require('express').Router)()
|
||||||
|
|
||||||
const startCase = require('lodash/startCase');
|
const startCase = require('lodash/startCase')
|
||||||
|
|
||||||
const mw = {
|
const mw = {
|
||||||
// employees: require('midwest-service-employees/middleware'),
|
// employees: require('midwest-service-employees/middleware'),
|
||||||
@ -24,7 +24,7 @@ const mw = {
|
|||||||
// roles: require('midwest-module-membership/services/roles/middleware'),
|
// roles: require('midwest-module-membership/services/roles/middleware'),
|
||||||
// users: require('../services/users/users-middleware'),
|
// users: require('../services/users/users-middleware'),
|
||||||
shim: require('midwest/factories/shim')(require('../config/shim')),
|
shim: require('midwest/factories/shim')(require('../config/shim')),
|
||||||
};
|
}
|
||||||
|
|
||||||
// const {
|
// const {
|
||||||
// isAuthenticated,
|
// isAuthenticated,
|
||||||
@ -33,7 +33,7 @@ const mw = {
|
|||||||
// redirectAuthorized,
|
// redirectAuthorized,
|
||||||
// } = require('midwest-module-membership/passport/authorization-middleware');
|
// } = require('midwest-module-membership/passport/authorization-middleware');
|
||||||
|
|
||||||
const allowedRoutes = ['forgot', 'reset', 'verify', 'login', 'register'];
|
const allowedRoutes = ['forgot', 'reset', 'verify', 'login', 'register']
|
||||||
|
|
||||||
// const config = {
|
// const config = {
|
||||||
// membership: require('../config/membership'),
|
// membership: require('../config/membership'),
|
||||||
@ -45,62 +45,61 @@ router
|
|||||||
// .get(new RegExp(`/(?!(${allowedRoutes.join('|')}))`), isAuthenticated, redirectUnauthorized(config.membership.paths.login))
|
// .get(new RegExp(`/(?!(${allowedRoutes.join('|')}))`), isAuthenticated, redirectUnauthorized(config.membership.paths.login))
|
||||||
// .get(new RegExp(`/(?=(${allowedRoutes.join('|')}))`), redirectAuthorized(isAuthenticated, '/'))
|
// .get(new RegExp(`/(?=(${allowedRoutes.join('|')}))`), redirectAuthorized(isAuthenticated, '/'))
|
||||||
.get('/', mw.shim, (req, res, next) => {
|
.get('/', mw.shim, (req, res, next) => {
|
||||||
res.preventFlatten = true;
|
res.preventFlatten = true
|
||||||
|
|
||||||
res.master = masterTemplate;
|
res.master = masterTemplate
|
||||||
|
|
||||||
next();
|
next()
|
||||||
})
|
})
|
||||||
// .get(new RegExp(`/${allowedRoutes.join('|')}`), redirectAuthenticated('/'), (req, res, next) => {
|
// .get(new RegExp(`/${allowedRoutes.join('|')}`), redirectAuthenticated('/'), (req, res, next) => {
|
||||||
// res.preventFlatten = true;
|
// res.preventFlatten = true;
|
||||||
|
|
||||||
// res.master = bareMasterTemplate;
|
// res.master = bareMasterTemplate;
|
||||||
|
|
||||||
// next();
|
// next();
|
||||||
// })
|
// })
|
||||||
// .get('/login', (req, res, next) => {
|
// .get('/login', (req, res, next) => {
|
||||||
// res.locals.scripts = ['/js/login.js'];
|
// res.locals.scripts = ['/js/login.js'];
|
||||||
|
|
||||||
// res.template = loginFormTemplate;
|
// res.template = loginFormTemplate;
|
||||||
|
|
||||||
// next();
|
// next();
|
||||||
// })
|
// })
|
||||||
// .get('/register', mw.invites.findByTokenAndEmail, (req, res, next) => {
|
// .get('/register', mw.invites.findByTokenAndEmail, (req, res, next) => {
|
||||||
// res.locals.scripts = ['/js/register.js'];
|
// res.locals.scripts = ['/js/register.js'];
|
||||||
|
|
||||||
// res.template = registerFormTemplate;
|
// res.template = registerFormTemplate;
|
||||||
|
|
||||||
// next();
|
// next();
|
||||||
// })
|
// })
|
||||||
// .get('/change-password', (req, res, next) => {
|
// .get('/change-password', (req, res, next) => {
|
||||||
// res.locals.scripts = ['/js/change-password.js'];
|
// res.locals.scripts = ['/js/change-password.js'];
|
||||||
|
|
||||||
// res.template = changePasswordFormTemplate;
|
// res.template = changePasswordFormTemplate;
|
||||||
|
|
||||||
// next();
|
// next();
|
||||||
// })
|
// })
|
||||||
// .get('/forgot-password', (req, res, next) => {
|
// .get('/forgot-password', (req, res, next) => {
|
||||||
// res.locals.scripts = ['/js/forgot-password.js'];
|
// res.locals.scripts = ['/js/forgot-password.js'];
|
||||||
|
|
||||||
// res.template = forgotPasswordFormTemplate;
|
// res.template = forgotPasswordFormTemplate;
|
||||||
|
|
||||||
// next();
|
// next();
|
||||||
// .get('/membership/users/:id', mw.publishers.getAll, mw.roles.getAll, mw.users.findById, (req, res, next) => {
|
// .get('/membership/users/:id', mw.publishers.getAll, mw.roles.getAll, mw.users.findById, (req, res, next) => {
|
||||||
// console.log(res.locals.roles);
|
// console.log(res.locals.roles);
|
||||||
// // res.locals.allRoles = res.locals.roles;
|
// // res.locals.allRoles = res.locals.roles;
|
||||||
// // console.log(res.locals);
|
// // console.log(res.locals);
|
||||||
// // res.locals.allPublishers = res.locals.publishers.filter((publisher) => !res.locals.user.publishers.some((p) => {
|
// // res.locals.allPublishers = res.locals.publishers.filter((publisher) => !res.locals.user.publishers.some((p) => {
|
||||||
// // return publisher._id.toString() === p._id.toString();
|
// // return publisher._id.toString() === p._id.toString();
|
||||||
// // }));
|
// // }));
|
||||||
// // delete res.locals.roles;
|
// // delete res.locals.roles;
|
||||||
// // delete res.locals.publishers;
|
// // delete res.locals.publishers;
|
||||||
// next();
|
// next();
|
||||||
// })
|
// })
|
||||||
// .get('/errors', mw.errors.formatQuery, mw.errors.paginate, mw.errors.find)
|
// .get('/errors', mw.errors.formatQuery, mw.errors.paginate, mw.errors.find)
|
||||||
// .get('/login')
|
// .get('/login')
|
||||||
// .get('/forgot')
|
// .get('/forgot')
|
||||||
// .get('/reset')
|
// .get('/reset')
|
||||||
// .get('/verify')
|
// .get('/verify')
|
||||||
;
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The main file that sets up the Express instance and node
|
* The main file that sets up the Express instance and node
|
||||||
@ -7,49 +7,49 @@
|
|||||||
* @type {Express instance}
|
* @type {Express instance}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
global.ENV = process.env.NODE_ENV || 'development';
|
global.ENV = process.env.NODE_ENV || 'development'
|
||||||
global.PWD = process.env.NODE_PWD || process.cwd();
|
global.PWD = process.env.NODE_PWD || process.cwd()
|
||||||
|
|
||||||
// modules > native
|
// modules > native
|
||||||
const p = require('path');
|
const p = require('path')
|
||||||
|
|
||||||
if (ENV === 'development') {
|
if (ENV === 'development') {
|
||||||
// output filename in console log and colour console.dir
|
// output filename in console log and colour console.dir
|
||||||
require('midwest/util/console');
|
require('midwest/util/console')
|
||||||
// needed so symlinked modules get access to main projects node_modules/
|
// needed so symlinked modules get access to main projects node_modules/
|
||||||
require('app-module-path').addPath(p.join(PWD, 'node_modules'));
|
require('app-module-path').addPath(p.join(PWD, 'node_modules'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// modules > 3rd party
|
// modules > 3rd party
|
||||||
const _ = require('lodash');
|
const _ = require('lodash')
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk')
|
||||||
const express = require('express');
|
const express = require('express')
|
||||||
// const passport = require('passport');
|
// const passport = require('passport');
|
||||||
const requireDir = require('require-dir');
|
const requireDir = require('require-dir')
|
||||||
|
|
||||||
// modules > express middlewares
|
// modules > express middlewares
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser')
|
||||||
// const session = require('express-session');
|
// const session = require('express-session');
|
||||||
// const cookieParser = require('cookie-parser');
|
// const cookieParser = require('cookie-parser');
|
||||||
|
|
||||||
// modules > midwest
|
// modules > midwest
|
||||||
const colorizeStack = require('midwest/util/colorize-stack');
|
const colorizeStack = require('midwest/util/colorize-stack')
|
||||||
|
|
||||||
// make error output stack pretty
|
// make error output stack pretty
|
||||||
process.on('uncaughtException', (err) => {
|
process.on('uncaughtException', (err) => {
|
||||||
console.error(chalk.red('UNCAUGHT EXCEPTION'));
|
console.error(chalk.red('UNCAUGHT EXCEPTION'))
|
||||||
if (err.stack) {
|
if (err.stack) {
|
||||||
console.error(colorizeStack(err.stack));
|
console.error(colorizeStack(err.stack))
|
||||||
} else {
|
} else {
|
||||||
console.error(err);
|
console.error(err)
|
||||||
}
|
}
|
||||||
process.exit(1);
|
process.exit(1)
|
||||||
});
|
})
|
||||||
|
|
||||||
// midwest modules and services configuration
|
// midwest modules and services configuration
|
||||||
require('./midwest');
|
require('./midwest')
|
||||||
|
|
||||||
const config = requireDir('./config', { camelcase: true });
|
const config = requireDir('./config', { camelcase: true })
|
||||||
|
|
||||||
const prewares = [
|
const prewares = [
|
||||||
express.static(config.dir.static, ENV === 'production' ? { maxAge: '1 year' } : null),
|
express.static(config.dir.static, ENV === 'production' ? { maxAge: '1 year' } : null),
|
||||||
@ -59,11 +59,11 @@ const prewares = [
|
|||||||
// session(config.session),
|
// session(config.session),
|
||||||
// passport.initialize(),
|
// passport.initialize(),
|
||||||
// passport.session(),
|
// passport.session(),
|
||||||
];
|
]
|
||||||
|
|
||||||
if (ENV === 'development') {
|
if (ENV === 'development') {
|
||||||
// only log requests to console in development mode
|
// only log requests to console in development mode
|
||||||
prewares.unshift(require('morgan')('dev'));
|
prewares.unshift(require('morgan')('dev'))
|
||||||
// prewares.push(require('midwest-module-membership/passport/automatic-login'));
|
// prewares.push(require('midwest-module-membership/passport/automatic-login'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,45 +73,47 @@ const postwares = [
|
|||||||
require('midwest/factories/error-handler')(config.errorHandler),
|
require('midwest/factories/error-handler')(config.errorHandler),
|
||||||
// respond
|
// respond
|
||||||
require('midwest/middleware/responder'),
|
require('midwest/middleware/responder'),
|
||||||
];
|
]
|
||||||
|
|
||||||
const server = express();
|
const server = express()
|
||||||
|
|
||||||
// get IP & whatnot from nginx proxy
|
// get IP & whatnot from nginx proxy
|
||||||
server.set('trust proxy', true);
|
server.set('trust proxy', true)
|
||||||
|
|
||||||
_.extend(server.locals, {
|
_.extend(server.locals, {
|
||||||
site: require('./config/site'),
|
site: require('./config/site'),
|
||||||
});
|
})
|
||||||
|
|
||||||
// override default response render method for
|
// override default response render method for
|
||||||
// more convenient use with marko
|
// more convenient use with marko
|
||||||
server.response.render = require('./render');
|
server.response.render = require('./render')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.locals.js = require(p.join(PWD, 'public/js.json'));
|
server.locals.js = require(p.join(PWD, 'public/js.json'))
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.locals.css = require(p.join(PWD, 'public/css.json'));
|
server.locals.css = require(p.join(PWD, 'public/css.json'))
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
// load prewares
|
// load prewares
|
||||||
server.use(...prewares);
|
server.use(...prewares)
|
||||||
|
|
||||||
// mount routers
|
// mount routers
|
||||||
server.use(require('./routers/index'));
|
server.use(require('./routers/index'))
|
||||||
server.use('/api', require('./routers/api'));
|
server.use('/api', require('./routers/api'))
|
||||||
// server.use('/auth', require('midwest-module-membership/passport/router'));
|
// server.use('/auth', require('midwest-module-membership/passport/router'));
|
||||||
|
|
||||||
// load postwares
|
// load postwares
|
||||||
server.use(...postwares);
|
server.use(...postwares)
|
||||||
|
|
||||||
// Only start Express server when it is the main module (ie not required by test)
|
// Only start Express server when it is the main module (ie not required by test)
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
server.http = server.listen(config.port, () => {
|
server.http = server.listen(config.port, () => {
|
||||||
console.info(`[${chalk.cyan('INIT')}] HTTP Server listening on port ${chalk.magenta(config.port)} (${chalk.yellow(ENV)})`);
|
console.info(
|
||||||
});
|
`[${chalk.cyan('INIT')}] HTTP Server listening on port ${chalk.magenta(config.port)} (${chalk.yellow(ENV)})`,
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = server;
|
module.exports = server
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user