jsql-neo 5.1.0 → 5.1.1
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/README.md +2 -0
- package/bin/jsql +1 -1
- package/index.js +1 -1
- package/lib/web_ui.js +17 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
## Why JSQL-NEO?
|
|
15
15
|
|
|
16
|
+
My web : https://jsql.vexify.top/
|
|
17
|
+
|
|
16
18
|
Most embedded databases make you choose: *native speed*, *portable WASM*, or *a familiar file format*.
|
|
17
19
|
JSQL-NEO gives you **all three in one install** — plus drop-in compatibility with the **two most popular
|
|
18
20
|
database protocols in the world**.
|
package/bin/jsql
CHANGED
|
@@ -21,7 +21,7 @@ const manager = new ModuleManager();
|
|
|
21
21
|
|
|
22
22
|
const RAW_ARGV = process.argv.slice(2);
|
|
23
23
|
|
|
24
|
-
const cli = yaggs()
|
|
24
|
+
const cli = yaggs({ pkg: require('../package.json') })
|
|
25
25
|
.usage('jsql <command> [options]')
|
|
26
26
|
.option('help', { alias: ['h'], type: 'boolean', description: 'Show help' })
|
|
27
27
|
.command('mod', 'Module management', (sub) => {
|
package/index.js
CHANGED
package/lib/web_ui.js
CHANGED
|
@@ -116,7 +116,8 @@ class WebUI {
|
|
|
116
116
|
this.readonly = !!opts.readonly;
|
|
117
117
|
this.host = opts.host || '127.0.0.1';
|
|
118
118
|
this.authToken = opts.authToken || null;
|
|
119
|
-
this.allowOrigin = opts.allowOrigin ||
|
|
119
|
+
this.allowOrigin = opts.allowOrigin || null;
|
|
120
|
+
this.echoOrigin = !opts.allowOrigin && !!this.authToken;
|
|
120
121
|
this.cache = new Map();
|
|
121
122
|
}
|
|
122
123
|
|
|
@@ -157,12 +158,16 @@ class WebUI {
|
|
|
157
158
|
async handle(req, res) {
|
|
158
159
|
const url = new URL(req.url, 'http://x');
|
|
159
160
|
const reqOrigin = req.headers.origin;
|
|
160
|
-
|
|
161
|
+
let corsOrigin = null;
|
|
162
|
+
if (this.allowOrigin) corsOrigin = this.allowOrigin;
|
|
163
|
+
else if (this.echoOrigin && reqOrigin) corsOrigin = reqOrigin;
|
|
161
164
|
const send = (code, obj) => {
|
|
162
165
|
const body = JSON.stringify(obj);
|
|
163
166
|
const headers = { 'Content-Type': 'application/json' };
|
|
164
|
-
if (
|
|
165
|
-
|
|
167
|
+
if (corsOrigin) {
|
|
168
|
+
headers['Access-Control-Allow-Origin'] = corsOrigin;
|
|
169
|
+
headers['Vary'] = 'Origin';
|
|
170
|
+
}
|
|
166
171
|
res.writeHead(code, headers);
|
|
167
172
|
res.end(body);
|
|
168
173
|
};
|
|
@@ -173,12 +178,14 @@ class WebUI {
|
|
|
173
178
|
return res.end(PAGE);
|
|
174
179
|
}
|
|
175
180
|
if (req.method === 'OPTIONS' && url.pathname.startsWith('/api/')) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
'Access-Control-Allow-
|
|
179
|
-
'Access-Control-Allow-
|
|
180
|
-
'
|
|
181
|
-
|
|
181
|
+
const h = {};
|
|
182
|
+
if (corsOrigin) {
|
|
183
|
+
h['Access-Control-Allow-Origin'] = corsOrigin;
|
|
184
|
+
h['Access-Control-Allow-Methods'] = 'GET,POST,OPTIONS';
|
|
185
|
+
h['Access-Control-Allow-Headers'] = 'Authorization,Content-Type';
|
|
186
|
+
h['Vary'] = 'Origin';
|
|
187
|
+
}
|
|
188
|
+
res.writeHead(204, h);
|
|
182
189
|
return res.end();
|
|
183
190
|
}
|
|
184
191
|
if (this.authToken && url.pathname.startsWith('/api/')) {
|