mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 17:37:14 +00:00
24 lines
586 B
JavaScript
24 lines
586 B
JavaScript
|
|
||
|
const openInEditor = require('open-in-editor')
|
||
|
|
||
|
module.exports = function openInEditorMiddleware(req, res) {
|
||
|
// Lazy load open-in-editor
|
||
|
const editor = openInEditor.configure(this.options.editor)
|
||
|
|
||
|
// Parse Query
|
||
|
const query = req.url.split('?')[1].split('&').reduce((q, part) => {
|
||
|
const s = part.split('=')
|
||
|
q[s[0]] = decodeURIComponent(s[1])
|
||
|
return q
|
||
|
}, {})
|
||
|
|
||
|
// eslint-disable-next-line no-console
|
||
|
console.log('[open in editor]', query.file)
|
||
|
|
||
|
editor.open(query.file).then(() => {
|
||
|
res.end('opened in editor!')
|
||
|
}).catch(err => {
|
||
|
res.end(err)
|
||
|
})
|
||
|
}
|