I had a project which requires logging in as admin and then the page redirects to the admin panel. Now, my project was working fine in Jade template but after upgrading to pug and renaming all views I am getting this problem:
Error: Not Found at /Users/uzayrhussain/Desktop/OOES2/app.js:53:13
This is login.pug
doctype html
html(lang='en')
head
body
// Top content
.top-content
.inner-bg
.container
.row
.col-sm-8.col-sm-offset-2.text
h1
strong Login
.row
.col-sm-3
a.btn.btn-info(href='/', role='button') Go Back!
.col-sm-6.form-box
.form-top
.form-top-left
h3 Fill the form to sign in:
.form-bottom
form.login-form(role='formlogin', action='login/#{method}', method='post')
.form-group
label.sr-only(for='form-username') Username
input#form-username.form-username.form-control(type='text', name='username', placeholder="username")
.form-group
label.sr-only(for='form-password') Password
input#form-password.form-password.form-control(type='password', name='password', placeholder="password")
button.btn(type='submit') Login
.col-sm-3
// Javascript
//if lt IE 10
App.js
var app = express();
require('./config/passport')(passport);
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({secret: 'my_app_secret'}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
var monk = require('monk');
var db = monk('localhost:27017/examdb');
var admin = require('./controllers/admin');
var login = require('./controllers/login_controller');
var index = require('./controllers/index');
app.use('/',index);
app.use('/login', login);
app.use('/admin', admin);
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
//app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
Aucun commentaire:
Enregistrer un commentaire