Express middleware to get a file content fragment by request to defined route. Based on source-fragment.
Install
npm install express-source-fragment
Usage
var express = ;var sourceFragment = ; var app = ; // There are few ways to setup:// - to trigger middleware on *GET* request to `/source-fragment`app; // - to trigger middleware on *any* request method to `/source-fragment`app; // - to trigger middleware on *any* request method to *any* path// (not recommended unless server's single purpose is a serving of source fragments)app;
After that you can use GET
requests like /source-fragment?file=foo/bar.js:2:5:4:12
to get a source fragment of foo/bar.js
that starts on line 2 column 5 and ends on line 4 column 12.
Using with webpack-dev-server
Although webpack-dev-server
uses express
to create a server, you have the same options to apply the middleware to it. The only difference is that you should define it in setup
method (see issue for details).
var server = // ... { app; };
API
sourceFragment([options]);
Options:
-
cwd
Type:
String
Default:''
(usesprocess.cwd()
)Working directory used when resolving paths.
Related projects
- source-fragment – package that do the main task of
express-source-fragment
, i.e. gets a source fragment. - express-open-in-editor – Express middleware to open a file in an editor by request, open-in-editor.
- babel-plugin-source-wrapper –
Babel
plugin that instruments source code to associate objects with location they defined in code base. - Component Inspector – developer tool to inspect components that can open component creation source location in editor. Has integrations for
React
,Backbone
and can be adopter for other frameworks.
License
MIT