-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (60 loc) · 1.6 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var express = require('express');
var path = require('path');
var session = require('express-session');
var FileStore = require('session-file-store')(session);
var bodyParser = require('body-parser');
var multer = require('multer');
var mysql = require('mysql');
var myConnection = require('express-myconnection');
// =================
// = Setup the app =
// =================
// The app itself
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.set('port', (process.env.PORT || 3000));
// ============================
// = Middleware configuration =
// ============================
// Setup serving static assets
app.use(express.static(path.join(__dirname, 'public')));
// Add session support
app.use(session({
secret: '...', // CHANGE THIS!!!
store: new FileStore(),
saveUninitialized: true,
resave: false
}));
// Setup bodyparser
app.use(bodyParser.urlencoded({extended: true}));
// Setup Multer
app.use(multer({
dest: './uploads/'
}));
// Setup MySQL
// Database configuration
var dbOptions = {
host: 'localhost',
user: 'root',
password: '',
database: 'sss-final'
};
// Add connection middleware
app.use(myConnection(mysql, dbOptions, 'single'));
// ===========
// = Routers =
// ===========
var testRouter = require('./routers/test');
app.use('/test', testRouter);
// This should be the ONLY route in this file!
app.get('/', function(req, res){
res.redirect('/test');
});
// =================
// = Start the app =
// =================
app.listen(app.get("port"), function(){
console.log("really started");
});