@rpcbase/server 0.21.0 → 0.25.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 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,17 @@ 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:${CLIENT_PORT}`, "localhost"]
33
+ console.log("SETUP CORS", cors_origins)
34
+ app.use(cors({
35
+ origin: cors_origins,
36
+ methods: ["GET", "POST"],
37
+ credentials: true // enable set-cookie
38
+ }))
39
+
22
40
  session(app)
23
41
 
24
42
  app.get("/api/ping", (req, res) => res.json({status: "ok"}))
@@ -6,7 +6,7 @@
6
6
  module.exports = (schema, options) => {
7
7
  console.log("MONGOOSE DELETE PLUGIN")
8
8
 
9
- schema.post(["deleteOne"], (arg, arg2) => {
9
+ schema.post("remove", (arg, arg2) => {
10
10
  console.log("DELETE WOWO", arg, arg2)
11
11
  })
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.21.0",
3
+ "version": "0.25.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",