@everneed/worker 1.0.2 → 1.1.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/index.js +19 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import postgres from "postgres"
|
|
2
2
|
import mongoose from "mongoose"
|
|
3
3
|
import { createClient } from "redis"
|
|
4
|
+
import { io } from "socket.io-client"
|
|
4
5
|
|
|
5
6
|
import rabbitmq from "./worker/rabbitmq.js"
|
|
6
7
|
import pseudoEnv from "./pseudoenv.js"
|
|
@@ -68,8 +69,26 @@ import pseudoEnv from "./pseudoenv.js"
|
|
|
68
69
|
.on("error", err => console.log("Redis Client Error", err))
|
|
69
70
|
// .connect()
|
|
70
71
|
}
|
|
72
|
+
/* Socketio */
|
|
73
|
+
let socketioInstance = ()=>{}
|
|
74
|
+
socketioInstance.config = (object)=>{
|
|
75
|
+
// config({
|
|
76
|
+
// ENV: value,
|
|
77
|
+
// ...
|
|
78
|
+
// })
|
|
79
|
+
/* Param Validation */
|
|
80
|
+
const allowed = new Set(["WEBSOCKET_HOST", "WEBSOCKET_PORT"])
|
|
81
|
+
if(new Set(Object.keys(object)).difference(allowed).size){
|
|
82
|
+
throw `illegal key on socketio.config(): Only ${Array.from(allowed).join(", ")} are allowed`
|
|
83
|
+
}
|
|
84
|
+
/* Env Add Process */
|
|
85
|
+
pseudoEnv.config(object)
|
|
86
|
+
/* Refresh Instance (force re-export) */
|
|
87
|
+
socketioInstance = io(`ws://${pseudoEnv.process.env.WEBSOCKET_HOST}:${pseudoEnv.process.env.WEBSOCKET_PORT}/`)
|
|
88
|
+
}
|
|
71
89
|
|
|
72
90
|
export { rabbitmq } // preserve seperate-dir for example
|
|
73
91
|
export { postgresInstance as postgres }
|
|
74
92
|
// export { mongooseInstance as mongoose }
|
|
75
93
|
export { redisInstance as redis }
|
|
94
|
+
export { socketioInstance as socketio }
|