@package-broker/adapter-node 0.7.0 → 0.7.2
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/package.json +1 -1
- package/src/index.ts +23 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serve } from '@hono/node-server';
|
|
2
|
-
import { createApp } from '@package-broker/core';
|
|
2
|
+
import { createApp, generateEncryptionKey } from '@package-broker/core';
|
|
3
3
|
import { config } from 'dotenv';
|
|
4
4
|
import { SqliteDriver } from './drivers/sqlite-driver.js';
|
|
5
5
|
import { FileSystemDriver } from './drivers/fs-driver.js';
|
|
@@ -85,11 +85,33 @@ async function start() {
|
|
|
85
85
|
queue = new MemoryQueueDriver();
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
// Get or generate ENCRYPTION_KEY
|
|
89
|
+
let encryptionKey = process.env.ENCRYPTION_KEY;
|
|
90
|
+
if (!encryptionKey) {
|
|
91
|
+
console.warn('');
|
|
92
|
+
console.warn('⚠️ ENCRYPTION_KEY not set - generating a temporary key for this session');
|
|
93
|
+
console.warn(' ⚠️ WARNING: This key will change on restart. Set ENCRYPTION_KEY for production!');
|
|
94
|
+
console.warn(' 📖 See: https://package.broker/docs/reference/configuration');
|
|
95
|
+
console.warn('');
|
|
96
|
+
encryptionKey = await generateEncryptionKey();
|
|
97
|
+
}
|
|
98
|
+
|
|
88
99
|
// Create App
|
|
89
100
|
const app = createApp({
|
|
90
101
|
database,
|
|
91
102
|
storage,
|
|
92
103
|
cache,
|
|
104
|
+
onInit: (app) => {
|
|
105
|
+
// Inject environment variables into c.env for Node.js adapter
|
|
106
|
+
app.use('*', async (c, next) => {
|
|
107
|
+
// Make c.env available and populate from process.env
|
|
108
|
+
(c.env as any) = {
|
|
109
|
+
...(c.env || {}),
|
|
110
|
+
ENCRYPTION_KEY: encryptionKey,
|
|
111
|
+
};
|
|
112
|
+
await next();
|
|
113
|
+
});
|
|
114
|
+
},
|
|
93
115
|
});
|
|
94
116
|
|
|
95
117
|
// Serve config.js dynamically
|