Basic app setup

This commit is contained in:
Timothy Warren 2016-02-19 16:17:59 -05:00
parent 2403bdfcee
commit b6dc717a00
15 changed files with 101 additions and 39 deletions

15
.gitignore vendored
View File

@ -1,5 +1,3 @@
# Created by https://www.gitignore.io/api/node,osx,webstorm,eclipse
### Node ### ### Node ###
# Logs # Logs
logs logs
@ -11,15 +9,6 @@ pids
*.pid *.pid
*.seed *.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration # node-waf configuration
.lock-wscript .lock-wscript
@ -65,9 +54,7 @@ Temporary Items
.apdisk .apdisk
# Don't commit generated docs # Don't commit generated docs
public/docs/* public/generated/*
public/api-docs/*
public/coverage/*
# Don't commit environment file # Don't commit environment file
.env .env

View File

@ -36,7 +36,12 @@ let errorHandlers = new Set([
output.error = err; output.error = err;
} }
res.json(output); res.render('error', {
title: `${err.status} ${err.message}`,
error: output,
});
//res.json(output);
}, },
]); ]);

View File

@ -1,15 +1,18 @@
'use strict'; 'use strict';
// Stupid template engine requires coffescript for some reason const handlebars = require('express-handlebars');
const cs = require('coffee-script');
cs.register();
const path = require('path'); const path = require('path');
const hulk = require('hulk-hogan');
module.exports.setup = (app) => { module.exports.setup = (app) => {
let viewPath = path.resolve(__dirname, '../views'); const baseViewDir = path.resolve(__dirname, '../views');
app.set('views', viewPath); app.set('views', baseViewDir);
app.set('view options', { layout: false }); app.engine('.stache', handlebars({
app.set('view engine', 'hulk'); defaultLayout: 'blog',
extname: '.stache',
layoutsDir: `${baseViewDir}/layouts/`,
partialsDir: `${baseViewDir}/partials/`,
}));
// use .stache files as a default view extension
app.set('view engine', '.stache');
}; };

13
app/controllers/admin.js Normal file
View File

@ -0,0 +1,13 @@
'use strict';
module.exports = {
'/': {
},
'/login': {
},
'/logout': {
},
};

View File

@ -2,19 +2,11 @@
module.exports = { module.exports = {
'/': { '/': {
// Get homepage // Get homepage
get: (req, res) => { get: (req, res) => {
return res.json({ return res.render('index', {
status: 200, title: 'Blog test page',
data: {
index: { title: 'Express' },
},
}); });
}, },
put: (req, res, next) => {
return next();
},
}, },
}; };

16
app/views/error.stache Normal file
View File

@ -0,0 +1,16 @@
<main>
<h1>{{error.status}}</h1>
<h2>{{error.message}}</h2>
{{#if error.error}}
<article>
<table>
<caption>Error Details</caption>
{{#each error as |value key|}}
<tr>
<td>{{key}}</td>
<td>{{value}}</td>
{{/each}}
</table>
</article>
{{/if}}
</main>

28
app/views/index.stache Normal file
View File

@ -0,0 +1,28 @@
<main>
<header>
<nav>
<ul>
<li><a href="#"><strong>First</strong></a></li>
<li><a href="#">Second</a></li>
<li><a href="#">Third</a></li>
<li><a href="#">Fourth</a></li>
</ul>
</nav>
</header>
<article>
<h1>Article</h1>
</article>
<aside>
<h1>Aside</h1>
</aside>
<section>
<h1>Section</h1>
</section>
<footer>
<p>&copy; Timothy J. Warren</p>
</footer>
</main>

View File

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
{{>head}}
<body>
{{{body}}}
</body>
</html>

View File

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
{{>blog/head}}
<body>
{{{body}}}
</body>
</html>

View File

@ -0,0 +1,5 @@
<head>
<meta charset="utf-8" />
<title>{{title}}</title>
<link rel="stylesheet" href="//cdn.rawgit.com/mblode/marx/master/css/marx.min.css">
</head>

View File

@ -155,7 +155,7 @@ gulp.task('src-docs', () => {
documentation({ documentation({
format: 'html', format: 'html',
}), }),
gulp.dest('public/docs'), gulp.dest('public/generated/docs'),
]); ]);
}); });
@ -165,7 +165,7 @@ gulp.task('src-docs', () => {
gulp.task('api-docs', (done) => { gulp.task('api-docs', (done) => {
apidoc({ apidoc({
src: 'app/', src: 'app/',
dest: 'public/api-docs/', dest: 'public/generated/api-docs/',
}, done); }, done);
}); });
@ -217,7 +217,7 @@ gulp.task('coverage', ['lint', 'pre-coverage'], () => {
return pipe(gulp.src(UNIT_TEST_FILES), [ return pipe(gulp.src(UNIT_TEST_FILES), [
mocha(MOCHA_SETTINGS), mocha(MOCHA_SETTINGS),
istanbul.writeReports({ istanbul.writeReports({
dir: 'public/coverage', dir: 'public/generated/coverage',
reporters:['lcov', 'lcovonly', 'html', 'text'], reporters:['lcov', 'lcovonly', 'html', 'text'],
}), }),
]); ]);

View File

@ -4,19 +4,18 @@
"axios": "^0.9.1", "axios": "^0.9.1",
"body-parser": "~1.13.2", "body-parser": "~1.13.2",
"ci-node-query": "^3.1.0", "ci-node-query": "^3.1.0",
"coffee-script": "^1.10.0",
"cookie-parser": "~1.3.5", "cookie-parser": "~1.3.5",
"debug": "~2.2.0", "debug": "~2.2.0",
"dotenv": "^2.0.0", "dotenv": "^2.0.0",
"errors": "^0.3.0", "errors": "^0.3.0",
"eslint": "^1.10.3", "eslint": "^1.10.3",
"express": "4.*", "express": "4.*",
"express-handlebars": "^3.0.0",
"express-session": "^1.13.0", "express-session": "^1.13.0",
"getargs": "0.0.8", "getargs": "0.0.8",
"glob": "^6.0.4", "glob": "^6.0.4",
"helmet": "^1.1.0", "helmet": "^1.1.0",
"highlight.js": "^9.1.0", "highlight.js": "^9.1.0",
"hulk-hogan": "0.0.9",
"lodash": "^4.5.0", "lodash": "^4.5.0",
"marked": "^0.3.5", "marked": "^0.3.5",
"morgan": "~1.6.1", "morgan": "~1.6.1",

View File

View File