@rpcbase/server 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/express/index.js +24 -0
- package/express/session.js +31 -0
- package/index.js +1 -0
- package/package.json +7 -1
package/express/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const express = require("express")
|
|
3
|
+
|
|
4
|
+
const session = require("./session")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module.exports = () => {
|
|
8
|
+
const app = express()
|
|
9
|
+
app.use(body_parser.json())
|
|
10
|
+
|
|
11
|
+
app.set("trust proxy", 1)
|
|
12
|
+
|
|
13
|
+
app.disable("x-powered-by")
|
|
14
|
+
app.set("etag", false)
|
|
15
|
+
|
|
16
|
+
app.use((req, res, next) => {
|
|
17
|
+
res.set("Cache-Control", "no-store")
|
|
18
|
+
next()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
session(app)
|
|
22
|
+
|
|
23
|
+
return app
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const session = require("express-session")
|
|
3
|
+
const redis = require("redis")
|
|
4
|
+
const validator = require("validator")
|
|
5
|
+
const redis_store = require("connect-redis")(session)
|
|
6
|
+
|
|
7
|
+
const {SESSION_STORE_PORT} = process.env
|
|
8
|
+
|
|
9
|
+
if (!validator.isPort(SESSION_STORE_PORT)) {
|
|
10
|
+
throw new Error("expected SESSION_STORE_PORT to be a valid port number")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const session_store_url = `redis://session-store:${SESSION_STORE_PORT}`
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
module.exports = (app) => {
|
|
17
|
+
const redis_client = redis.createClient({
|
|
18
|
+
url: session_store_url
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
app.use(
|
|
22
|
+
session({
|
|
23
|
+
store: new redis_store({client: redis_client}),
|
|
24
|
+
proxy: true,
|
|
25
|
+
saveUninitialized: false,
|
|
26
|
+
// TODO: fix session secret
|
|
27
|
+
secret: "session secret wowow",
|
|
28
|
+
resave: false,
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "SSPL-1.0",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,8 +10,14 @@
|
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 0"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"body-parser": "1.19.1",
|
|
14
|
+
"connect-redis": "6.0.0",
|
|
13
15
|
"dotenv": "10.0.0",
|
|
16
|
+
"express": "4.17.2",
|
|
17
|
+
"express-session": "1.17.2",
|
|
14
18
|
"glob": "7.2.0",
|
|
19
|
+
"redis": "3.1.2",
|
|
20
|
+
"validator": "13.7.0",
|
|
15
21
|
"yargs": "17.3.1"
|
|
16
22
|
}
|
|
17
23
|
}
|