pwi-plata-type 0.2.7 → 0.2.10

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/bin/plata.ts CHANGED
@@ -2,6 +2,10 @@ import { PlataClusterManager, PlataClusterMsg } from "../libs/cluster.js"
2
2
  import { loadEnvProjectFile } from "../libs/env.js"
3
3
  import { loadExpressRoutes } from "../libs/routes.js"
4
4
  import express, { Express } from "express"
5
+ import { createServer } from 'node:https'
6
+ import fs from 'node:fs'
7
+ import { PlataDirs } from "../libs/tools.js"
8
+ import path from 'node:path'
5
9
 
6
10
  const main = async () => {
7
11
  const clusterLib = new PlataClusterManager();
@@ -70,10 +74,37 @@ const main = async () => {
70
74
  })
71
75
  })
72
76
 
73
- app.listen(port, () => {
74
- console.log(`Iniciando Worker Express na porta ${port}`)
75
- setTimeout(() => process.removeAllListeners('exit'), 500)
76
- })
77
+ if (!process.env._PLATA_API_SSL_KEY || !process.env._PLATA_API_SSL_CERT) {
78
+ console.log(`Nenhum certificado configurado na env ${process.env.ENV}:`)
79
+ console.log(`_PLATA_API_SSL_KEY: ${process.env._PLATA_API_SSL_KEY}`)
80
+ console.log(`_PLATA_API_SSL_CERT: ${process.env._PLATA_API_SSL_CERT}`)
81
+
82
+ app.listen(port, () => {
83
+ console.log(`Iniciando Worker Express na porta ${port}`)
84
+ setTimeout(() => process.removeAllListeners('exit'), 500)
85
+ })
86
+ } else {
87
+ console.log('Iniciando a Plata com ssl usando os arquivos:')
88
+ console.log(`key: ${process.env._PLATA_API_SSL_KEY}`)
89
+ console.log(`cert: ${process.env._PLATA_API_SSL_CERT}`)
90
+
91
+ const https = createServer({
92
+ cert: fs.readdirSync(path.normalize(path.join(
93
+ PlataDirs.getProjectDir(),
94
+ process.env._PLATA_API_SSL_CERT
95
+ ))),
96
+ key: fs.readdirSync(path.normalize(path.join(
97
+ PlataDirs.getProjectDir(),
98
+ process.env._PLATA_API_SSL_KEY
99
+ )))
100
+ }, app)
101
+
102
+ https.listen(port, () => {
103
+ console.log(`Iniciando Worker Express na porta ${port} com SSL`)
104
+ setTimeout(() => process.removeAllListeners('exit'), 500)
105
+ })
106
+ }
107
+
77
108
  } else {
78
109
  await clusterLib.loadWorker()
79
110
  }
package/libs/tools.ts CHANGED
@@ -11,6 +11,8 @@ export interface PlataError {
11
11
  error?: any
12
12
  }
13
13
 
14
+ export type PlataResultado<T> = (T & { errorID?: undefined }) | PlataError
15
+
14
16
  export module PlataDirs {
15
17
  export function getProjectDir(): string {
16
18
  return path.resolve('.')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pwi-plata-type",
3
- "version": "0.2.7",
3
+ "version": "0.2.10",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "bin": {
@@ -5,4 +5,6 @@ ENV=debug
5
5
 
6
6
  # Configurações da plata:
7
7
  PORT=3050
8
- _PLATA_API_ROOT=/api
8
+ _PLATA_API_ROOT=/api
9
+ _PLATA_API_SSL_KEY=
10
+ _PLATA_API_SSL_CERT=
@@ -6,4 +6,6 @@ ENV=homolog
6
6
 
7
7
  # Configurações da plata:
8
8
  PORT=3050
9
- _PLATA_API_ROOT=/api
9
+ _PLATA_API_ROOT=/api
10
+ _PLATA_API_SSL_KEY=
11
+ _PLATA_API_SSL_CERT=
@@ -6,4 +6,6 @@ ENV=prod
6
6
 
7
7
  # Configurações da plata:
8
8
  PORT=3050
9
- _PLATA_API_ROOT=/api
9
+ _PLATA_API_ROOT=/api
10
+ _PLATA_API_SSL_KEY=
11
+ _PLATA_API_SSL_CERT=