Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d493dfc
Showing
14 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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 | ||
|
||
# hide .env file | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var path = require('path'); | ||
|
||
module.exports = { | ||
'config': path.resolve('./db', 'config.json'), | ||
'migrations-path': path.resolve('./db', 'migrations'), | ||
'models-path': path.resolve('./db', 'models'), | ||
'seeders-path': path.resolve('./db', 'seeders') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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 methodOverride = require('method-override'); | ||
const session = require('express-session'); | ||
const passport = require('passport'); | ||
|
||
//require routes and set to variables | ||
const index = require('./routes/index'); | ||
const user = require('./routes/user'); | ||
|
||
|
||
const app = express(); | ||
|
||
//override with POST having ?_method | ||
app.use(methodOverride('_method')); | ||
|
||
//require dotenv and use config method | ||
require('dotenv').config(); | ||
|
||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'ejs'); | ||
|
||
// 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 })); | ||
//express session and passport middleware | ||
|
||
app.use(cookieParser()); | ||
app.use(require('node-sass-middleware')({ | ||
src: path.join(__dirname, 'public'), | ||
dest: path.join(__dirname, 'public'), | ||
indentedSyntax: false, | ||
sourceMap: true | ||
})); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
//app.use routes, always after middleware | ||
app.use('/', index); | ||
app.use('/user', user); | ||
|
||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
var 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require('../app'); | ||
var debug = require('debug')('techie: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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"development": { | ||
"password": null, | ||
"database": "movies_app_development", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"production": { | ||
"use_env_variable": "DATABASE_URL" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var Sequelize = require('sequelize'); | ||
var basename = path.basename(module.filename); | ||
var env = process.env.NODE_ENV || 'development'; | ||
var config = require(__dirname + '/../config.json')[env]; | ||
var db = {}; | ||
|
||
if (config.use_env_variable) { | ||
var sequelize = new Sequelize(process.env[config.use_env_variable]); | ||
} else { | ||
var sequelize = new Sequelize( | ||
config.database, | ||
process.env['DATABASE_USERNAME'], | ||
config.password, | ||
config | ||
); | ||
} | ||
|
||
fs | ||
.readdirSync(__dirname) | ||
.filter(function(file) { | ||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); | ||
}) | ||
.forEach(function(file) { | ||
var model = sequelize['import'](path.join(__dirname, file)); | ||
db[model.name] = model; | ||
}); | ||
|
||
Object.keys(db).forEach(function(modelName) { | ||
if (db[modelName].associate) { | ||
db[modelName].associate(db); | ||
} | ||
}); | ||
|
||
db.sequelize = sequelize; | ||
db.Sequelize = Sequelize; | ||
|
||
module.exports = db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "techie", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "node ./bin/www", | ||
"dev": "nodemon ./bin/www" | ||
}, | ||
"dependencies": { | ||
"bcryptjs": "^2.4.0", | ||
"body-parser": "~1.15.2", | ||
"cookie-parser": "~1.4.3", | ||
"debug": "~2.2.0", | ||
"dotenv": "^4.0.0", | ||
"ejs": "~2.5.2", | ||
"express": "~4.14.0", | ||
"express-session": "^1.15.0", | ||
"method-override": "^2.3.7", | ||
"morgan": "~1.7.0", | ||
"node-sass-middleware": "0.9.8", | ||
"nodemon": "^1.11.0", | ||
"passport": "^0.3.2", | ||
"passport-local": "^1.0.0", | ||
"pg": "^6.1.2", | ||
"pg-hstore": "^2.3.2", | ||
"sequelize": "^3.30.1", | ||
"sequelize-cli": "^2.5.1", | ||
"serve-favicon": "~2.3.0" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.11.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET home page. */ | ||
router.get('/', function(req, res, next) { | ||
res.render('index', { title: 'Express' }); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1><%= message %></h1> | ||
<h2><%= error.status %></h2> | ||
<pre><%= error.stack %></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title><%= title %></title> | ||
<link rel='stylesheet' href='/stylesheets/style.css' /> | ||
</head> | ||
<body> | ||
<h1><%= title %></h1> | ||
<p>Welcome to <%= title %></p> | ||
</body> | ||
</html> |