Skip to content

Commit 095c273

Browse files
authored
assignment: AO - 08 (#21)
1 parent eaa1f52 commit 095c273

File tree

20 files changed

+2997
-0
lines changed

20 files changed

+2997
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
/shoot/screenshots
3+
4+
# dependencies
5+
/node_modules
6+
/.pnp
7+
.pnp.js
8+
9+
# testing
10+
/coverage
11+
12+
# production
13+
/build
14+
15+
# misc
16+
.DS_Store
17+
.env.local
18+
.env.development.local
19+
.env.test.local
20+
.env.production.local
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var favicon = require('serve-favicon');
4+
var logger = require('morgan');
5+
var cookieParser = require('cookie-parser');
6+
var bodyParser = require('body-parser');
7+
var session = require('express-session');
8+
9+
var auth = require('./routes/auth');
10+
11+
// TODO: require the shoot module.
12+
let shoot = require('./routes/shoot');
13+
14+
var app = express();
15+
16+
var passport = require('passport');
17+
18+
// view engine setup
19+
app.set('views', path.join(__dirname, 'views'));
20+
app.set('view engine', 'pug');
21+
22+
23+
// uncomment after placing your favicon in /public
24+
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
25+
app.use(logger('dev'));
26+
app.use(bodyParser.json());
27+
app.use(bodyParser.urlencoded({ extended: false }));
28+
app.use(cookieParser());
29+
app.use(session({
30+
secret : "superfancysessionsecretSFSS",
31+
resave: false,
32+
saveUninitialized: false
33+
}));
34+
35+
// now all parsing middleware is there and we can use more advanced middleware.
36+
37+
// this initializes
38+
app.use(passport.initialize());
39+
app.use(passport.session());
40+
41+
42+
// forwarder if the user is logged in
43+
app.use('/', [express.static(path.join(__dirname, 'public'))]);
44+
app.use('/secret', [auth.ensureAuthenticated, express.static(path.join(__dirname, 'secret'))]);
45+
46+
app.use('/auth', auth);
47+
48+
// TODO: insert add the router of the shoot module (just like auth).
49+
app.use('/shoot', [auth.ensureAuthenticated, shoot]);
50+
51+
52+
// catch 404 and forward to error handler
53+
app.use(function(req, res, next) {
54+
var err = new Error('Not Found');
55+
err.status = 404;
56+
next(err);
57+
});
58+
59+
60+
61+
62+
// error handlers
63+
64+
// development error handler
65+
// will print stacktrace
66+
if (app.get('env') === 'development') {
67+
app.use(function(err, req, res, next) {
68+
res.status(err.status || 500);
69+
res.render('error', {
70+
message: err.message,
71+
error: err
72+
});
73+
});
74+
}
75+
76+
// production error handler
77+
// no stacktraces leaked to user
78+
app.use(function(err, req, res, next) {
79+
res.status(err.status || 500);
80+
res.render('error', {
81+
message: err.message,
82+
error: {}
83+
});
84+
});
85+
86+
module.exports = app;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('ScreenshotApp:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Created by Tobi on 06/12/2016.
3+
*/
4+
5+
// from https://github.com/manjeshpv/node-express-passport-mysql/
6+
// config/database.js
7+
module.exports = {
8+
'connection': {
9+
'host': 'localhost', // you can probably leave this.
10+
'user': 'root', // if you have root access, leave this
11+
'password': '', // if you use XAMPP and did not reconfigure it, the empty password is correct.
12+
'database': 'mmn1617' // make sure to create this database first.
13+
},
14+
'users_table': 'users'
15+
};

0 commit comments

Comments
 (0)