@rpcbase/server 0.22.0 → 0.23.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.
Files changed (2) hide show
  1. package/express/index.js +15 -0
  2. package/package.json +2 -1
package/express/index.js CHANGED
@@ -1,9 +1,13 @@
1
1
  /* @flow */
2
+ const cors = require("cors")
2
3
  const express = require("express")
3
4
  const body_parser = require("body-parser")
4
5
 
5
6
  const session = require("./session")
6
7
 
8
+ const {APP_DOMAIN} = process.env
9
+ const is_production = process.env.IS_PRODUCTION === "yes"
10
+
7
11
 
8
12
  module.exports = () => {
9
13
  const app = express()
@@ -12,6 +16,9 @@ module.exports = () => {
12
16
  app.set("trust proxy", 1)
13
17
 
14
18
  app.disable("x-powered-by")
19
+
20
+
21
+ // tmp disable aggressive caching
15
22
  app.set("etag", false)
16
23
 
17
24
  app.use((req, res, next) => {
@@ -19,6 +26,14 @@ module.exports = () => {
19
26
  next()
20
27
  })
21
28
 
29
+ // CORS
30
+ const cors_origins = is_production ? [`*.${APP_DOMAIN}`, APP_DOMAIN] : ["*"]
31
+ app.use(cors({
32
+ origin: cors_origins,
33
+ methods: ["GET", "POST"],
34
+ credentials: true // enable set-cookie
35
+ }))
36
+
22
37
  session(app)
23
38
 
24
39
  app.get("/api/ping", (req, res) => res.json({status: "ok"}))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -12,6 +12,7 @@
12
12
  "dependencies": {
13
13
  "body-parser": "1.19.1",
14
14
  "connect-redis": "6.0.0",
15
+ "cors": "2.8.5",
15
16
  "dotenv": "10.0.0",
16
17
  "express": "4.17.2",
17
18
  "express-session": "1.17.2",