errorOverlayMiddleware.js 732 B

1234567891011121314151617181920212223
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. 'use strict';
  8. const launchEditor = require('./launchEditor');
  9. const launchEditorEndpoint = require('./launchEditorEndpoint');
  10. module.exports = function createLaunchEditorMiddleware() {
  11. return function launchEditorMiddleware(req, res, next) {
  12. if (req.url.startsWith(launchEditorEndpoint)) {
  13. const lineNumber = parseInt(req.query.lineNumber, 10) || 1;
  14. const colNumber = parseInt(req.query.colNumber, 10) || 1;
  15. launchEditor(req.query.fileName, lineNumber, colNumber);
  16. res.end();
  17. } else {
  18. next();
  19. }
  20. };
  21. };