added recommeded changes from tslint

This commit is contained in:
jacobbogers
2017-05-19 06:11:06 +02:00
parent ac0e8900bf
commit afdadfe885
3 changed files with 48 additions and 57 deletions

View File

@@ -1,9 +1,7 @@
import express = require('express');
import session = require('express-session');
var app = express();
let app = express();
app.use(session({
secret: 'keyboard cat',
@@ -14,7 +12,7 @@ app.use(session({
name: 'connect.sid',
store: new session.MemoryStore(),
cookie: { path: '/', httpOnly: true, secure: false, maxAge: null },
genid: (req: express.Request): string => { return ''; },
genid: (req: express.Request): string => '',
rolling: false,
resave: true,
proxy: true,
@@ -22,21 +20,20 @@ app.use(session({
unset: 'keep'
}));
interface MySession extends Express.Session {
views: number;
}
app.use(function(req, res, next) {
var sess = <MySession>req.session;
app.use((req, res, next) => {
let sess = <MySession>req.session;
if (sess.views) {
sess.views++
res.setHeader('Content-Type', 'text/html')
res.write('<p>views: ' + sess.views + '</p>')
res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>')
res.end()
sess.views++;
res.setHeader('Content-Type', 'text/html');
res.write('<p>views: ' + sess.views + '</p>');
res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>');
res.end();
} else {
sess.views = 1
res.end('welcome to the session demo. refresh!')
sess.views = 1;
res.end('welcome to the session demo. refresh!');
}
});

View File

@@ -1,26 +1,22 @@
// Type definitions for express-session
// Project: https://www.npmjs.org/package/express-session
// Definitions by: Jacob Bogers <http://github.com/jacobbogers
// Definitions by: Hiroki Horiuchi <https://github.com/horiuchi/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Definitions by: Jacob Bogers <http://github.com/jacobbogers
/// <reference types="node" />
/// <reference types="express" />
declare namespace Express {
export interface Request {
interface Request {
session?: Session;
sessionID?: string;
}
export interface SessionData {
interface SessionData {
[key: string]: any;
cookie: Express.SessionCookieData;
}
export interface SessionCookieData {
interface SessionCookieData {
originalMaxAge: number;
path: string;
maxAge: number;
@@ -30,22 +26,19 @@ declare namespace Express {
expires: Date | boolean;
}
export interface SessionCookie extends SessionCookieData {
serialize: (name: string, value: string) => string;
interface SessionCookie extends SessionCookieData {
serialize(name: string, value: string): string;
}
export interface Session extends SessionData {
interface Session extends SessionData {
id: string;
regenerate: (callback: (err: any) => void) => void;
destroy: (callback: (err: any) => void) => void;
reload: (callback: (err: any) => void) => void;
save: (callback: (err: any) => void) => void;
touch: (callback: (err: any) => void) => void;
regenerate(callback: (err: any) => void): void;
destroy(callback: (err: any) => void): void;
reload(callback: (err: any) => void): void;
save(callback: (err: any) => void): void;
touch(callback: (err: any) => void): void;
cookie: SessionCookie;
}
}
declare module "express-session" {
@@ -55,12 +48,12 @@ declare module "express-session" {
function session(options?: session.SessionOptions): express.RequestHandler;
namespace session {
export interface SessionOptions {
interface SessionOptions {
secret: string;
name?: string;
store?: Store | MemoryStore;
cookie?: express.CookieOptions;
genid?: (req: express.Request) => string;
genid?(req: express.Request): string;
rolling?: boolean;
resave?: boolean;
proxy?: boolean;
@@ -68,39 +61,38 @@ declare module "express-session" {
unset?: string;
}
export interface BaseMemoryStore {
get: (sid: string, callback: (err: any, session: Express.Session) => void) => void;
set: (sid: string, session: Express.Session, callback: (err: any) => void) => void;
destroy: (sid: string, callback: (err: any) => void) => void;
length?: (callback: (err: any, length: number) => void) => void;
clear?: (callback: (err: any) => void) => void;
interface BaseMemoryStore {
get(sid: string, callback: (err: any, session: Express.Session) => void): void;
set(sid: string, session: Express.Session, callback: (err: any) => void): void;
destroy(sid: string, callback: (err: any) => void): void;
length?(callback: (err: any, length: number) => void): void;
clear?(callback: (err: any) => void): void;
}
export abstract class Store extends node.EventEmitter {
abstract class Store extends node.EventEmitter {
constructor(config?: any);
regenerate(req: express.Request, fn: (err: any) => any): void;
load(sid: string, fn: (err: any, session: Express.Session) => any): void;
createSession(req: express.Request, sess: Express.SessionData): void;
get: (sid: string, callback: (err: any, session: Express.Session) => void) => void;
set: (sid: string, session: Express.Session, callback: (err: any) => void) => void;
destroy: (sid: string, callback: (err: any) => void) => void;
all: (callback: (err: any, obj: { [sid: string]: Express.SessionData; }) => void) => void;
length: (callback: (err: any, length: number) => void) => void;
clear: (callback: (err: any) => void) => void;
get(sid: string, callback: (err: any, session: Express.Session) => void): void;
set(sid: string, session: Express.Session, callback: (err: any) => void): void;
destroy(sid: string, callback: (err: any) => void): void;
all(callback: (err: any, obj: { [sid: string]: Express.SessionData; }) => void): void;
length(callback: (err: any, length: number) => void): void;
clear(callback: (err: any) => void): void;
}
export class MemoryStore implements BaseMemoryStore {
get: (sid: string, callback: (err: any, session: Express.Session) => void) => void;
set: (sid: string, session: Express.Session, callback: (err: any) => void) => void;
destroy: (sid: string, callback: (err: any) => void) => void;
all: (callback: (err: any, obj: { [sid: string]: Express.Session; }) => void) => void;
length: (callback: (err: any, length: number) => void) => void;
clear: (callback: (err: any) => void) => void;
class MemoryStore implements BaseMemoryStore {
get(sid: string, callback: (err: any, session: Express.Session) => void): void;
set(sid: string, session: Express.Session, callback: (err: any) => void): void;
destroy(sid: string, callback: (err: any) => void): void;
all(callback: (err: any, obj: { [sid: string]: Express.Session; }) => void): void;
length(callback: (err: any, length: number) => void): void;
clear(callback: (err: any) => void): void;
}
}
export = session;
}

View File

@@ -0,0 +1,2 @@
{
"extends": "dtslint/dt.json" }