Sup_File/app.js

84 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-05-03 14:15:57 +00:00
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');
2018-05-30 21:51:57 +00:00
var faceBK = require('./auth/facebook');
2018-05-03 14:15:57 +00:00
var app = express();
2018-05-30 21:51:57 +00:00
var session = require('express-session');
2018-05-03 14:15:57 +00:00
//var http = require("http").Server(app).listen(80);
//console.log("Server Started!");
//DB
//file
2018-05-08 20:31:43 +00:00
var upload = require("express-fileupload");
2018-05-03 14:15:57 +00:00
//var morgan = require('morgan');
var mongoose = require('mongoose');
var passport = require('passport');
2018-06-07 06:44:15 +00:00
//var session = require('express-session');
2018-05-03 14:15:57 +00:00
var config = require('./config/database');
//DB
//mongoose.Promise = require('bluebird');
mongoose.connect(config.database);
2018-06-07 06:44:15 +00:00
app.use(function(req, res, next) {
2018-06-07 17:47:13 +00:00
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
res.setHeader('Access-Control-Allow-Credentials', true);
2018-06-07 06:44:15 +00:00
next();
});
2018-05-21 12:08:44 +00:00
app.use(session({
secret: 's3cr3t',
resave: true,
saveUninitialized: true
}));
2018-05-03 14:15:57 +00:00
app.use(passport.initialize());
2018-05-30 21:51:57 +00:00
app.use(passport.session());
2018-05-03 14:15:57 +00:00
app.use(logger('dev'));
app.use(bodyParser.json());
// app.use(upload());
app.use(bodyParser.urlencoded({'extended':'false'}));
2018-05-30 21:51:57 +00:00
//app.use(express.static(path.join(__dirname, 'dist')));
app.use(express.static(path.join(__dirname, 'other')));
2018-05-03 14:15:57 +00:00
//bizarrr
2018-05-08 20:31:43 +00:00
app.use('/public',express.static(path.join(__dirname, './public')));
2018-05-03 14:15:57 +00:00
app.use('/books', express.static(path.join(__dirname, 'dist')));
2018-06-07 06:44:15 +00:00
app.use('/home', express.static(path.join(__dirname, 'dist')));
app.use('/main/:id', express.static(path.join(__dirname, 'dist')));
app.use('/login', express.static(path.join(__dirname, 'dist')));
app.use('/signup', express.static(path.join(__dirname, 'dist')));
2018-06-24 19:31:22 +00:00
app.use('/download/:id', express.static(path.join(__dirname, 'dist')));
2018-06-07 06:44:15 +00:00
app.use('/api', api);
app.set('view engine', 'pug');
2018-05-30 21:51:57 +00:00
//app.use('/api', faceBK);
2018-05-03 14:15:57 +00:00
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
2018-06-07 06:44:15 +00:00
2018-05-03 14:15:57 +00:00
// 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;