Sup_File/app.js
2018-05-31 00:19:29 +02:00

75 lines
1.8 KiB
JavaScript

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var bodyParser = require('body-parser');
var api = require('./routes/api');
var faceBK = require('./auth/facebook');
var app = express();
var session = require('express-session');
//var http = require("http").Server(app).listen(80);
//console.log("Server Started!");
//DB
//file
var upload = require("express-fileupload");
//var morgan = require('morgan');
var mongoose = require('mongoose');
var passport = require('passport');
var session = require('express-session');
var config = require('./config/database');
//DB
//mongoose.Promise = require('bluebird');
mongoose.connect(config.database);
app.use(session({
secret: 's3cr3t',
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(logger('dev'));
app.use(bodyParser.json());
// app.use(upload());
app.use(bodyParser.urlencoded({'extended':'false'}));
//app.use(express.static(path.join(__dirname, 'dist')));
app.use(express.static(path.join(__dirname, 'other')));
//bizarrr
app.use('/public',express.static(path.join(__dirname, './public')));
app.use('/books', express.static(path.join(__dirname, 'dist')));
app.use('/api', api);
//app.use('/api', faceBK);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use(session({
secret: 's3cr3t',
resave: true,
saveUninitialized: true
}));
// 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;