forgot.js
/* eslint-disable */
import express from 'express';
const router = express.Router();
router.get('/', (req, res, next) => {
console.log('forgot');
res.render('forgot', { title: 'Forgot Password' });
})
export default router;

app.js
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import Debug from 'debug';
import express from 'express';
import logger from 'morgan';
// import favicon from 'serve-favicon'
import path from 'path';
import sassMiddleware from 'node-sass-middleware';
import session from 'express-session';
import validator from 'express-validator';
import { MongoClient } from 'mongodb';
import index from './routes/index';
import forgot from './routes/forgot';
// import dashboard from './routes/dashboard';
const url = 'mongodb://localhost:27017/portal';
MongoClient.connect(url, (err, db) => {
if (err) throw err;
console.log('Database created!');
db.close();
});
const app = express();
const debug = Debug('students-registration-portal:app');
app.set('views', path.join(__dirname, 'views'));
// view engine setup
app.set('view engine', 'pug');
// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(validator());
app.use(session({ secret: 'jesse', saveUninitialized: true, resave: true, cookie: { maxAge: 60000 } }));
app.use(sassMiddleware({
src: path.join(__dirname, 'public'),
dest: path.join(__dirname, 'public'),
indentedSyntax: true,
sourceMap: true
}));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/forgot', forgot);
// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
/* eslint no-unused-vars: 0 */
app.use((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');
});
// Handle uncaughtException
process.on('uncaughtException', (err) => {
debug('Caught exception: %j', err);
process.exit(1);
});
export default app;
这里,索引路由正常,但忘记路由不起作用,它将我重定向到错误页面。
我使用了yoman es6 express generator。
console.log('忘了')语句正在运行,但res.render(...)无效(即使我在它之前放置了一个return语句)。
我在索引路径中使用了与忘记路线相同的逻辑。
forgot.pug
extends layout
block content
.center.center_cont
.container.ms-u-slideRightIn40
p.ms-font-xxl Sign In
.container.ms-u-slideRightIn20
form(action='/', method='POST')
.ms-TextField.text_box
label.ms-Label E-mail
input.ms-TextField-field(type="email", value=email, name="email", id="email")
button.ms-Button.ms-Button--primary(type='submit')
span.ms-Button-label Send Email
br
br
a(href='/register') create an account