Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Holmes committed Jan 22, 2017
0 parents commit 1ff360c
Show file tree
Hide file tree
Showing 21 changed files with 2,940 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
@@ -0,0 +1,30 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.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
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/cli/shrinkwrap#caveats
node_modules

# Debug log from npm
npm-debug.log
1 change: 1 addition & 0 deletions Procfile
@@ -0,0 +1 @@
web: npm start
46 changes: 46 additions & 0 deletions app.js
@@ -0,0 +1,46 @@
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');

const index = require('./app_server/routes/index');
const users = require('./app_server/routes/users');

const app = express();

// view engine setup
app.set('views', path.join(__dirname, 'app_server', 'views'));
app.set('view engine', 'pug');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', index);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

module.exports = app;
8 changes: 8 additions & 0 deletions app_server/controllers/main.js
@@ -0,0 +1,8 @@
/* GET home page */
const index = function(req, res){
res.render('index', { title: 'Express' });
};

module.exports = {
index
};
8 changes: 8 additions & 0 deletions app_server/routes/index.js
@@ -0,0 +1,8 @@
const express = require('express');
const router = express.Router();
const ctrlMain = require('../controllers/main');

/* GET home page. */
router.get('/', ctrlMain.index);

module.exports = router;
9 changes: 9 additions & 0 deletions app_server/routes/users.js
@@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});

module.exports = router;
6 changes: 6 additions & 0 deletions app_server/views/error.pug
@@ -0,0 +1,6 @@
extends layout

block content
h1= message
h2= error.status
pre #{error.stack}
5 changes: 5 additions & 0 deletions app_server/views/index.pug
@@ -0,0 +1,5 @@
extends layout

block content
h1= title
p Welcome to #{title}
13 changes: 13 additions & 0 deletions app_server/views/layout.pug
@@ -0,0 +1,13 @@
doctype html
html
head
meta(name='viewport', content='width=device-width, initial-scale=1.0')
title= title
link(rel='stylesheet', href='/stylesheets/bootstrap.min.css')
link(rel='stylesheet', href='/font-awesome/css/font-awesome.min.css')
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
script(src='https://code.jquery.com/jquery-3.1.1.slim.min.js')
script(src='https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js')
script(src='/javascripts/bootstrap.min.js')
90 changes: 90 additions & 0 deletions bin/www
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('book-code:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
17 changes: 17 additions & 0 deletions package.json
@@ -0,0 +1,17 @@
{
"name": "book-code",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.2",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.14.0",
"morgan": "~1.7.0",
"pug": "~2.0.0-beta6",
"serve-favicon": "~2.3.0"
}
}
4 changes: 4 additions & 0 deletions public/font-awesome/css/font-awesome.min.css

Large diffs are not rendered by default.

Binary file added public/font-awesome/fonts/FontAwesome.otf
Binary file not shown.
Binary file not shown.

0 comments on commit 1ff360c

Please sign in to comment.