diff --git a/express/express-tests.ts b/express/express-tests.ts index 27ba253c1..45e6b643e 100644 --- a/express/express-tests.ts +++ b/express/express-tests.ts @@ -20,7 +20,7 @@ app.use(express.session()); // Session-persisted message middleware -app.use(function (req, res, next) { +app.use((req: express.Request, res: express.Response, next) => { var err = req.session.error , msg = req.session.success; delete req.session.error; @@ -40,7 +40,7 @@ var users = { // when you create a user, generate a salt // and hash the password ('foobar' is the pass here) -hash('foobar', function (err, salt, hash) { +hash('foobar', (err, salt, hash) => { if (err) throw err; // store the salt & hash in the "db" users.tj.salt = salt; @@ -58,11 +58,11 @@ function authenticate(name, pass, fn) { // apply the same algorithm to the POSTed password, applying // the hash against the pass / salt, if there is a match we // found the user - hash(pass, user.salt, function (err, hash) { + hash(pass, user.salt, (err, hash) => { if (err) return fn(err); if (hash == user.hash) return fn(null, user); fn(new Error('invalid password')); - }) + }); } function restrict(req: express.Request, res: express.Response, next?: Function) { @@ -74,32 +74,32 @@ function restrict(req: express.Request, res: express.Response, next?: Function) } } -app.get('/', function (req, res) { +app.get('/', (req: express.Request, res: express.Response) => { res.redirect('login'); }); -app.get('/restricted', restrict, function (req, res) { +app.get('/restricted', restrict, (req: express.Request, res: express.Response) => { res.send('Wahoo! restricted area, click to logout'); }); -app.get('/logout', function (req, res) { +app.get('/logout', (req: express.Request, res: express.Response) => { // destroy the user's session to log them out // will be re-created next request - req.session.destroy(function () { + req.session.destroy(() => { res.redirect('/'); }); }); -app.get('/login', function (req, res) { +app.get('/login', (req: express.Request, res: express.Response) => { res.render('login'); }); -app.post('/login', function (req, res) { - authenticate(req.body.username, req.body.password, function (err, user) { +app.post('/login', (req: express.Request, res: express.Response) => { + authenticate(req.body.username, req.body.password, (err, user) => { if (user) { // Regenerate session when signing in // to prevent fixation - req.session.regenerate(function () { + req.session.regenerate(() => { // Store the user's primary key // in the session store to be retrieved, // or in this case the entire user object @@ -139,7 +139,7 @@ while (n--) { app.use(express.logger('dev')); -app.get('/', function (req, res) { +app.get('/', (req: express.Request, res: express.Response) => { res.render('pets', { pets: pets }); }); @@ -148,24 +148,24 @@ console.log('Express listening on port 3000'); ///////////// -app.get('/', function (req, res) { +app.get('/', (req: express.Request, res: express.Response) => { res.format({ - html: function () { - res.send('