launch-editor-middleware 2.10.0 → 2.11.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/index.js +19 -5
- package/package.json +8 -2
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const url = require('url')
|
|
2
1
|
const path = require('path')
|
|
3
2
|
const launch = require('launch-editor')
|
|
4
3
|
|
|
@@ -15,13 +14,28 @@ module.exports = (specifiedEditor, srcRoot, onErrorCallback) => {
|
|
|
15
14
|
|
|
16
15
|
srcRoot = srcRoot || process.cwd()
|
|
17
16
|
|
|
18
|
-
return function launchEditorMiddleware
|
|
19
|
-
|
|
17
|
+
return function launchEditorMiddleware(req, res) {
|
|
18
|
+
let url
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const fullUrl = req.url.startsWith('http') ? req.url : `http://localhost${req.url}`
|
|
22
|
+
url = new URL(fullUrl)
|
|
23
|
+
// eslint-disable-next-line no-unused-vars
|
|
24
|
+
} catch (_err) {
|
|
25
|
+
res.statusCode = 500
|
|
26
|
+
res.end(`launch-editor-middleware: invalid URL.`)
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const file = url.searchParams.get('file')
|
|
20
31
|
if (!file) {
|
|
21
32
|
res.statusCode = 500
|
|
22
|
-
res.end(
|
|
33
|
+
res.end(
|
|
34
|
+
`launch-editor-middleware: required query param "file" is missing.`
|
|
35
|
+
)
|
|
23
36
|
} else {
|
|
24
|
-
|
|
37
|
+
const resolved = file.startsWith('file://') ? file : path.resolve(srcRoot, file)
|
|
38
|
+
launch(resolved, specifiedEditor, onErrorCallback)
|
|
25
39
|
res.end()
|
|
26
40
|
}
|
|
27
41
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "launch-editor-middleware",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.1",
|
|
4
4
|
"description": "express middleware for launching editor",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js"
|
|
8
|
+
],
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "git+https://github.com/yyx990803/launch-editor.git"
|
|
@@ -19,6 +22,9 @@
|
|
|
19
22
|
},
|
|
20
23
|
"homepage": "https://github.com/yyx990803/launch-editor#readme",
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"launch-editor": "^2.
|
|
25
|
+
"launch-editor": "^2.11.1"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "node --test --experimental-test-module-mocks"
|
|
23
29
|
}
|
|
24
30
|
}
|