@rpcbase/server 0.19.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.
package/database.js CHANGED
@@ -2,15 +2,20 @@
2
2
  const mongoose = require("mongoose")
3
3
  const validator = require("validator")
4
4
 
5
- const {DATABASE_PORT} = process.env
5
+ const {DATABASE_PORT, DATABASE_NAME} = process.env
6
6
 
7
7
  if (typeof DATABASE_PORT === "string" && !validator.isPort(DATABASE_PORT)) {
8
8
  throw new Error("expected DATABASE_PORT to be a valid port number")
9
9
  }
10
10
 
11
- const mongo_url = `mongodb://database:${DATABASE_PORT}/commit-queue`
11
+ if (typeof DATABASE_NAME !== "string") {
12
+ throw new Error("expected DATABASE_NAME to be a string")
13
+ }
14
+
15
+ const mongo_url = `mongodb://database:${DATABASE_PORT}/${DATABASE_NAME}`
12
16
 
13
17
  module.exports = async() => {
14
18
  const ret = await mongoose.connect(mongo_url)
15
19
  // TODO: handle connection ret
20
+ // console.log(ret)
16
21
  }
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/mongoose/index.js CHANGED
@@ -1,4 +1,8 @@
1
1
  /* @flow */
2
2
  const mongoose = require("mongoose")
3
3
 
4
+ const rts_delete_plugin = require("./rts_delete_plugin")
5
+
6
+ mongoose.plugin(rts_delete_plugin)
7
+
4
8
  module.exports = mongoose
@@ -0,0 +1,12 @@
1
+ /* @flow */
2
+
3
+ // fixes the mongodb issue with missing fullDocument in change streams
4
+ // that is required for dispatching to proper sockets in real time state
5
+
6
+ module.exports = (schema, options) => {
7
+ console.log("MONGOOSE DELETE PLUGIN")
8
+
9
+ schema.post("remove", (arg, arg2) => {
10
+ console.log("DELETE WOWO", arg, arg2)
11
+ })
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.19.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",