express.js with jade templating engine

时间:2016-07-06 11:04:08

标签: node.js express pug

我有一个项目,我正在努力让路由正确以呈现我的玉文件,golf.jade。

这是我的routing.js文件

var passport = require('passport'),
http = require('http'),
routes = require('./routes'),
user = require('./routes/user'),
game = require('./routes/game'),
golf = require('./routes/golf'),
webhooks = require('./routes/webhooks');

var mainapp = null;

function ensureAuthenticated(req, res, next) {
    if (req.isAuthenticated()) return next();
    res.set('X-Auth-Required', 'true');
   //res.redirect('/login?returnUrl=' +      encodedURIComponent(req.originalUrl));
    res.redirect('/login');
}


function ensureAdmin(req, res, next) {
    if (req.user.canPlayRoleOf('admin')) return next();
    res.redirect('/');
}

function ensureActive(req, res, next) {
    console.log("ensuring active");
    if (req.user.active) return next();
   res.redirect("/404");
}

function ensureAccount(req, res, next) {
    if (req.user.Email) return next();
    //if (req.user.canPlayRoleOf('account')) return next();
    res.redirect('/account/externalconnect');
}

function csrf(req, res, next) {
    res.locals.token = req.csrfToken();
    next();
}

exports = module.exports = function (app) {
    mainapp = app;
    routes.setMainApp(app);
    user.setMainApp(app);
    game.setMainApp(app);
    golf.setMainApp(app);
    webhooks.setMainApp(app);


    app.get('/ping.html', function (req, res) {
        res.render('ping');
    });

    app.get('/', csrf, ensureAuthenticated, ensureActive, routes.index);
    app.get('/404', csrf, routes.pagemissing);
    app.get('/error', csrf, routes.error);

    //integration webhooks
    app.post("/partner/stripe/q12kp8VZLf", webhooks.stripe)

    //sports
    app.get('/:sport/week', csrf, ensureAuthenticated, ensureActive,               game.week);
app.get('/:sport/coming', csrf, ensureAuthenticated, ensureActive, routes.coming);

//golf
app.get('/:sport/golf', csrf, ensureAuthenticated, ensureActive, golf);

//results
app.get('/:sport/results', csrf, ensureAuthenticated, ensureActive, game.results);
app.get('/:sport/results/:yr/getYearAccuracy', csrf, ensureAuthenticated, ensureActive, game.getYearAccuracy);

// game
app.get('/:sport/game/:id', csrf, ensureAuthenticated, ensureActive, game.game);
app.get('/:sport/game/:id/info', csrf, ensureAuthenticated, ensureActive, game.getGame);
app.get('/:sport/game/:id/details', csrf, ensureAuthenticated, ensureActive, game.getGameDetails);
app.get('/:sport/game/:id/results', csrf, ensureAuthenticated, ensureActive, game.getGameResults);
app.get('/:sport/game/:id/predictions', csrf, ensureAuthenticated, ensureActive, game.getGamePredictions);
app.get('/:sport/game/:id/history', csrf, ensureAuthenticated, ensureActive, game.getGameHistoryForTeams);
app.post('/:sport/game/:id/unlock', csrf, ensureAuthenticated, ensureActive, game.unlockgame);

// season
app.get('/:sport/season/:yr/weeks', csrf, ensureAuthenticated, ensureActive, game.getSeasonWeeks);
app.get('/:sport/season/:yr/weeks/current', csrf, ensureAuthenticated, ensureActive, game.getCurrentGameWeek);
app.get('/:sport/season/:yr/week/:wk', csrf, ensureAuthenticated, ensureActive, game.getGameWeek);
app.get('/:sport/season/:yr/week/:wk/predictions', csrf, ensureAuthenticated, ensureActive, game.getGameWeekPredictions);
app.get('/:sport/season/:yr/week/:wk/accuracy', csrf, ensureAuthenticated, ensureActive, game.getGameWeekAccuracy);
app.get('/:sport/season/:yr/team/:id', csrf, ensureAuthenticated, ensureActive, game.getTeamSeason);
app.get('/:sport/season/:yr/week/:wk/unlocks', csrf, ensureAuthenticated, ensureActive, game.getGameUnlocksForUser);

// profile
app.get('/profile', csrf, ensureAuthenticated, ensureActive, user.profile);

app.get('/profile/data', csrf, ensureAuthenticated, ensureActive, user.getprofile);
app.post('/profile/save', csrf, ensureAuthenticated, ensureActive, user.saveprofile);

// subscription
app.post('/profile/subscribe', csrf, ensureAuthenticated, ensureActive, user.subscribe);
app.get('/profile/subscriptions/available', csrf, ensureAuthenticated, ensureActive, user.getsubscriptions);
app.get('/profile/subscriptions/current', csrf, ensureAuthenticated, ensureActive, user.getusersubscription);

// billing
app.get('/profile/billing/current', csrf, ensureAuthenticated, ensureActive, user.getbillinginfo);


// registration
app.get('/register', csrf, user.register);
app.post('/registeruser', csrf, user.registeruser);

//forgot password
app.get('/forgot', csrf, user.forgot);
app.post('/resetaccount', csrf, user.resetaccount);
app.post('/updatepassword', csrf, ensureAuthenticated, ensureActive, user.updatepassword);

// login
app.get('/logout', csrf, user.logout);
app.get('/login', csrf, user.login);
app.post('/login', csrf, function (req, res, next) {
    passport.authenticate('local', function (err, user, info) {
        if (err) {
            return next(err);
        }

        if (!user) {
            req.session.message = [info.message];
            return res.json({ result: { code: 2, title: "Invalid login", message: "The username and password combination are not recognized. [" + info.message + "]" } });
        }
        req.logIn(user, function (err) {
            if (err) {
                return next(err);
            }
            return res.json({ result: { code: 0 } });
            //return res.redirect('/');
        });
    })(req, res, next);
});

};

我的app.js文件是我的epress项目的主文件,它引用了这个文件。我是带有jade模板的node.js / express.js的新手。我希望弄清楚我需要更改或添加以使路由正常工作。我在我要查看的视图文件夹中有一个golf.jade模板。

希望尽快解决这个问题我已经看过并尝试了几乎所有可以找到的教程,寻找方向,提前致谢

__斯科特

0 个答案:

没有答案