Skip to content

Commit d03797a

Browse files
authored
Merge pull request #57 from bodgery/cookie-session
Switch to Express/Cookie-Session
2 parents b7cc03e + 84cb1d3 commit d03797a

11 files changed

Lines changed: 65 additions & 175 deletions

File tree

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
Dockerfile
33
*.Dockerfile
44
node_modules
5-
!node_modules/connect-pg-simple/table.sql

app.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as c from "./src/context";
33
import * as Tokens from "csrf";
44
import * as express from "express";
55
import * as handlebars from "express-handlebars";
6-
import * as session from "express-session";
6+
import session = require("cookie-session"); // CommonJS Typescript workaround: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
77
import * as fs from "fs";
88
import * as shortid from "shortid";
99
import * as request_funcs from "./src/request_funcs";
@@ -107,17 +107,11 @@ function setup_app_params( conf, db, typeorm_connection, logger )
107107
let use_secure_cookie = (conf['deployment_type'] == "prod");
108108
let session_options = {
109109
secret: conf.session_secret
110-
,resave: false
111-
,saveUninitialized: true
112-
,cookie: {
113-
maxAge: conf.session_length_sec
114-
,sameSite: true
115-
,secure: use_secure_cookie
116-
,httpOnly: true
117-
}
110+
,maxAge: conf.session_length_sec
111+
,sameSite: true
112+
,secure: use_secure_cookie
113+
,httpOnly: true
118114
};
119-
let session_store = db.session_store( session );
120-
if(session_store) session_options['store'] = session_store;
121115

122116
let app = express();
123117
app.use( session( session_options ) );

database.Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
FROM postgres:alpine
22

33
ADD sql/pg.sql /docker-entrypoint-initdb.d/01_create_tables.sql
4-
ADD node_modules/connect-pg-simple/table.sql /docker-entrypoint-initdb.d/02_sessions.sql

package-lock.json

Lines changed: 45 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
"dependencies": {
1313
"@types/assert": "^1.4.2",
1414
"@types/bcrypt": "^3.0.0",
15-
"@types/connect-pg-simple": "^4.2.0",
15+
"@types/cookie-session": "^2.0.41",
1616
"@types/express": "^4.16.1",
17-
"@types/express-session": "^1.15.12",
1817
"@types/js-yaml": "^3.12.0",
1918
"@types/nconf": "^0.10.0",
2019
"@types/pg": "^7.4.14",
@@ -25,13 +24,12 @@
2524
"assert": "^1.4.1",
2625
"bcrypt": "^5.0.0",
2726
"body-parser": "^1.18.3",
28-
"connect-pg-simple": ">=6.0.1",
27+
"cookie-session": "^1.4.0",
2928
"crypto-random-string": "^3.0.1",
3029
"csrf": "^3.1.0",
3130
"express": "^4.16.4",
3231
"express-handlebars": "^3.0.2",
3332
"express-oauth-server": "^2.0.0",
34-
"express-session": "^1.16.1",
3533
"googleapis": "^40.0.0",
3634
"js-yaml": "^3.13.1",
3735
"logger": "^0.0.1",
@@ -58,6 +56,7 @@
5856
"mocha": "^8.1.3",
5957
"sinon": "^9.0.3",
6058
"supertest": "^3.3.0",
59+
"supertest-session": "^4.1.0",
6160
"ts-mocha": "^6.0.0",
6261
"ts-node": "^8.0.3"
6362
}

sql/rebuild_pg.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ DB_PASS=`grep "db_password:" config.yaml | perl -E 'say( (split /:\s*/, <>)[1] )
1010
psql -f sql/clear_pg_tables.sql ${DB}
1111
psql -f sql/pg.sql ${DB}
1212
#psql -f sql/test_log_data.sql ${DB}
13-
psql -f node_modules/connect-pg-simple/table.sql ${DB}
1413

1514
npx typeorm-model-generator \
1615
-h localhost \

src/db-mock.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,6 @@ export class MockDB
380380
success_callback();
381381
}
382382

383-
session_store( express_session )
384-
{
385-
return null;
386-
}
387-
388383
add_token(
389384
username: string
390385
,token: string

src/db-pg.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as db_impl from "./db";
22
import * as pg from "pg";
33
import * as pg_escape from "pg-escape";
4-
import * as session from "connect-pg-simple";
54

65

76
let no_rows_callback_builder = (member_id, callback) => {
@@ -679,15 +678,6 @@ export class PG
679678
);
680679
}
681680

682-
session_store( express_session )
683-
{
684-
let pg_session = session( express_session );
685-
let full_session = new pg_session({
686-
pool: this.pool
687-
});
688-
return full_session;
689-
}
690-
691681
is_token_allowed(
692682
token: string
693683
,success_callback: () => void

0 commit comments

Comments
 (0)