123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- var express = require('express');
- var path = require('path');
- var logger = require('morgan');
- var compression = require('compression');
- var methodOverride = require('method-override');
- var session = require('express-session');
- var flash = require('express-flash');
- var bodyParser = require('body-parser');
- var expressValidator = require('express-validator');
- var dotenv = require('dotenv');
- var nunjucks = require('nunjucks');
- var mongoose = require('mongoose');
- var passport = require('passport');
- var wildcardSubdomains = require('wildcard-subdomains');
- // Load environment variables from .env file
- dotenv.load();
- // Controllers
- var HomeController = require('./controllers/home');
- var userController = require('./controllers/user');
- var contactController = require('./controllers/contact');
- var campanhaController = require('./controllers/campanha');
- var uploadController = require('./controllers/upload');
- var sobreController = require('./controllers/sobre');
- var privacidadeController = require('./controllers/privacidade');
- var timeController = require('./controllers/time');
- var termosController = require('./controllers/termos');
- var voluntariadoController = require('./controllers/voluntariado');
- var faqController = require('./controllers/faq');
- // Passport OAuth strategies
- require('./config/passport');
- var app = express();
- mongoose.connect(process.env.DB_PATH);
- mongoose.connection.on('error', function() {
- console.log('MongoDB Connection Error. Please make sure that MongoDB is running.');
- process.exit(1);
- });
- // view engine setup
- nunjucks.configure('views', {
- autoescape: true,
- express: app
- });
- app.set('view engine', 'html');
- app.set('port', process.env.PORT || 3321);
- app.use(compression());
- app.use(logger('dev'));
- app.use(bodyParser.json());
- app.use(bodyParser.urlencoded({ extended: false }));
- app.use(expressValidator());
- app.use(methodOverride('_method'));
- app.use(session({ secret: process.env.SESSION_SECRET, resave: true, saveUninitialized: true }));
- app.use(flash());
- app.use(passport.initialize());
- app.use(passport.session());
- app.use(function(req, res, next) {
- res.locals.user = req.user;
- res.locals.baseurl = process.env.BASEURL;
- next();
- });
- app.use(express.static(path.join(__dirname, 'public')));
- //routers
- // Home
- app.get('/', HomeController.index);
- app.get('/novacampanha', userController.ensureAuthenticated, campanhaController.newCampanhaGet);
- app.post('/novacampanha', userController.ensureAuthenticated, campanhaController.newCampanhaPost);
- app.delete('/minhascampanhas', userController.ensureAuthenticated, campanhaController.campanhaDelete);
- //upload
- app.post('/upload', userController.ensureAuthenticated, uploadController.uploadImage);
- uploadDir = path.join(__dirname, '/public/media/');
- app.get('/minhascampanhas', campanhaController.minhascampanhasGet);
- app.get('/sobre', sobreController.index);
- app.get('/privacidade', privacidadeController.index);
- app.get('/time', timeController.index);
- app.get('/termos', termosController.index);
- app.get('/voluntariado', voluntariadoController.index);
- app.get('/faq', faqController.index);
- app.get('/contato', contactController.contactGet);
- app.post('/contato', contactController.contactPost);
- app.get('/account', userController.ensureAuthenticated, userController.accountGet);
- app.put('/account', userController.ensureAuthenticated, userController.accountPut);
- app.delete('/account', userController.ensureAuthenticated, userController.accountDelete);
- app.get('/signup', userController.signupGet);
- app.post('/signup', userController.signupPost);
- app.get('/login', userController.loginGet);
- app.post('/login', userController.loginPost);
- app.get('/forgot', userController.forgotGet);
- app.post('/forgot', userController.forgotPost);
- app.get('/reset/:token', userController.resetGet);
- app.post('/reset/:token', userController.resetPost);
- app.get('/logout', userController.logout);
- app.get('/unlink/:provider', userController.ensureAuthenticated, userController.unlink);
- app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email', 'user_location'] }));
- app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/', failureRedirect: '/login' }));
- app.get('/auth/twitter', passport.authenticate('twitter'));
- app.get('/auth/twitter/callback', passport.authenticate('twitter', { successRedirect: '/', failureRedirect: '/login' }));
- app.get('/auth/github', passport.authenticate('github', { scope: [ 'user:email profile repo' ] }));
- app.get('/auth/github/callback', passport.authenticate('github', { successRedirect: '/', failureRedirect: '/login' }));
- app.get('/:urlname', campanhaController.campanhaGet);
- app.get('/c/:urlname', campanhaController.campanhaGet);
- app.get('/:urlname/exterior', campanhaController.exteriorGet);
- // Production error handler
- if (app.get('env') === 'production') {
- app.use(function(err, req, res, next) {
- console.error(err.stack);
- res.sendStatus(err.status || 500);
- });
- }
- app.listen(app.get('port'), function() {
- console.log('Express server listening on port ' + app.get('port'));
- });
- module.exports = app;
|