@rpcbase/server 0.22.0 → 0.26.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 +19 -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 is_production = process.env.IS_PRODUCTION === "yes"
9
+ const {APP_DOMAIN, CLIENT_PORT} = process.env
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,18 @@ module.exports = () => {
19
26
  next()
20
27
  })
21
28
 
29
+ // CORS
30
+ const cors_origins = is_production ?
31
+ [`*.${APP_DOMAIN}`, APP_DOMAIN] :
32
+ [`http://localhost:*`, "localhost"]
33
+ // [`http://localhost:${CLIENT_PORT}`, "localhost"]
34
+ console.log("SETUP CORS", cors_origins)
35
+ app.use(cors({
36
+ origin: cors_origins,
37
+ methods: ["GET", "POST"],
38
+ credentials: true // enable set-cookie
39
+ }))
40
+
22
41
  session(app)
23
42
 
24
43
  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.26.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",