simplehttpserver
Advanced tools
Sorry, the diff of this file is not supported yet
+61
-34
@@ -23,24 +23,3 @@ <?xml version="1.0" encoding="UTF-8"?> | ||
| <component name="FileEditorManager"> | ||
| <leaf> | ||
| <file leaf-file-name="simplehttpserver.js" pinned="false" current-in-tab="true"> | ||
| <entry file="file://$PROJECT_DIR$/simplehttpserver.js"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.75386596"> | ||
| <caret line="87" column="63" selection-start-line="87" selection-start-column="63" selection-end-line="87" selection-end-column="63" /> | ||
| <folding /> | ||
| </state> | ||
| </provider> | ||
| </entry> | ||
| </file> | ||
| <file leaf-file-name="package.json" pinned="false" current-in-tab="false"> | ||
| <entry file="file://$PROJECT_DIR$/package.json"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="-8.125"> | ||
| <caret line="13" column="4" selection-start-line="13" selection-start-column="4" selection-end-line="13" selection-end-column="4" /> | ||
| <folding /> | ||
| </state> | ||
| </provider> | ||
| </entry> | ||
| </file> | ||
| </leaf> | ||
| <leaf /> | ||
| </component> | ||
@@ -91,3 +70,2 @@ <component name="IdeDocumentHistory"> | ||
| <panes> | ||
| <pane id="Scope" /> | ||
| <pane id="ProjectPane"> | ||
@@ -114,6 +92,7 @@ <subPane> | ||
| <pane id="Scratches" /> | ||
| <pane id="Scope" /> | ||
| </panes> | ||
| </component> | ||
| <component name="PropertiesComponent"> | ||
| <property name="last_opened_file_path" value="$PROJECT_DIR$/../eventsourceserver" /> | ||
| <property name="last_opened_file_path" value="$PROJECT_DIR$/../../experimental/booxtv" /> | ||
| <property name="WebServerToolWindowFactoryState" value="false" /> | ||
@@ -180,5 +159,5 @@ <property name="HbShouldOpenHtmlAsHb" value="" /> | ||
| <frame x="0" y="23" width="1440" height="873" extended-state="6" /> | ||
| <editor active="true" /> | ||
| <editor active="false" /> | ||
| <layout> | ||
| <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.15138888" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" /> | ||
| <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.15138888" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" /> | ||
| <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" /> | ||
@@ -188,7 +167,5 @@ <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" /> | ||
| <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" /> | ||
| <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" /> | ||
@@ -198,5 +175,7 @@ <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" /> | ||
| <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> | ||
| <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> | ||
| </layout> | ||
@@ -223,3 +202,3 @@ </component> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="20" column="35" selection-start-line="20" selection-start-column="35" selection-end-line="20" selection-end-column="35" /> | ||
| <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" /> | ||
| <folding /> | ||
@@ -229,5 +208,13 @@ </state> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/simplehttpserver.ssl.js"> | ||
| <entry file="file://$PROJECT_DIR$/package.json"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="13" column="4" selection-start-line="13" selection-start-column="4" selection-end-line="13" selection-end-column="4" /> | ||
| <folding /> | ||
| </state> | ||
| </provider> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/simplehttpserver.js"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" /> | ||
@@ -238,5 +225,29 @@ <folding /> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/package.json"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="13" column="4" selection-start-line="13" selection-start-column="4" selection-end-line="13" selection-end-column="4" /> | ||
| <folding /> | ||
| </state> | ||
| </provider> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/simplehttpserver.js"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="87" column="63" selection-start-line="87" selection-start-column="63" selection-end-line="87" selection-end-column="63" /> | ||
| <folding /> | ||
| </state> | ||
| </provider> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/package.json"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="13" column="4" selection-start-line="13" selection-start-column="4" selection-end-line="13" selection-end-column="4" /> | ||
| <folding /> | ||
| </state> | ||
| </provider> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/simplehttpserver.js"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="20" column="35" selection-start-line="20" selection-start-column="35" selection-end-line="20" selection-end-column="35" /> | ||
@@ -287,6 +298,6 @@ <folding /> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/package.json"> | ||
| <entry file="file://$PROJECT_DIR$/simplehttpserver.js"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="-8.125"> | ||
| <caret line="13" column="4" selection-start-line="13" selection-start-column="4" selection-end-line="13" selection-end-column="4" /> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="20" column="35" selection-start-line="20" selection-start-column="35" selection-end-line="20" selection-end-column="35" /> | ||
| <folding /> | ||
@@ -298,2 +309,10 @@ </state> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.0"> | ||
| <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" /> | ||
| <folding /> | ||
| </state> | ||
| </provider> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/simplehttpserver.ssl.js"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.35246995"> | ||
@@ -307,3 +326,3 @@ <caret line="18" column="0" selection-start-line="17" selection-start-column="0" selection-end-line="18" selection-end-column="0" /> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.75386596"> | ||
| <state vertical-scroll-proportion="0.072164945"> | ||
| <caret line="87" column="63" selection-start-line="87" selection-start-column="63" selection-end-line="87" selection-end-column="63" /> | ||
@@ -314,3 +333,11 @@ <folding /> | ||
| </entry> | ||
| <entry file="file://$PROJECT_DIR$/package.json"> | ||
| <provider selected="true" editor-type-id="text-editor"> | ||
| <state vertical-scroll-proportion="0.25930852"> | ||
| <caret line="13" column="4" selection-start-line="13" selection-start-column="4" selection-end-line="13" selection-end-column="4" /> | ||
| <folding /> | ||
| </state> | ||
| </provider> | ||
| </entry> | ||
| </component> | ||
| </project> |
+3
-4
| { | ||
| "name": "simplehttpserver", | ||
| "description": "Simple HTTP Server for static files", | ||
| "description": "Simple HTTP Server for static files. Intended as testing and development tool", | ||
| "author": "Teemu Ikonen <teemu.ikonen@ıki.fi>", | ||
| "version": "0.0.6", | ||
| "version": "0.1.0", | ||
| "bin": "./cli.js", | ||
@@ -16,3 +16,3 @@ "engine": "node >= 0.10.0", | ||
| "license": "MIT", | ||
| "repository" : { | ||
| "repository" : { | ||
| "type" : "git", | ||
@@ -22,2 +22,1 @@ "url" : "https://github.com/tikonen/blog/tree/master/simplehttpserver" | ||
| } | ||
+34
-5
@@ -7,2 +7,4 @@ var express = require('express'), | ||
| send = require('send'), | ||
| https = require('https'), | ||
| escape = require('querystring').escape, | ||
| morgan = require('morgan'); | ||
@@ -84,6 +86,20 @@ // bodyparser = require('body-parser'); | ||
| function htmlsafe( str ) { | ||
| var tbl = { | ||
| '&': '&', | ||
| '<': '<', | ||
| '>': '>', | ||
| '"': '"', | ||
| "'": ''' | ||
| }; | ||
| var safestr = ''; | ||
| for(var i=0; i < str.length; i++) { | ||
| safestr += tbl[str[i]] || str[i]; | ||
| } | ||
| return safestr; | ||
| } | ||
| // Reads directory content and builds HTML response | ||
| function directoryHTML( res, urldir, pathname, list ) { | ||
| var ulist = []; | ||
| function sendHTML( list ) { | ||
@@ -93,5 +109,5 @@ res.setHeader('Content-Type', 'text/html; charset=utf-8'); | ||
| '<html>\n' + | ||
| '<title>Directory listing for '+urldir+'</title>\n' + | ||
| '<title>Directory listing for '+htmlsafe(urldir)+'</title>\n' + | ||
| '<body>\n' + | ||
| '<h2>Directory listing for '+urldir+'</h2>\n' + | ||
| '<h2>Directory listing for '+htmlsafe(urldir)+'</h2>\n' + | ||
| '<hr><ul>\n' + | ||
@@ -113,6 +129,8 @@ list.join('\n') + | ||
| if ( !stat ) cb(); | ||
| var link = escape(item); | ||
| item = htmlsafe(item); | ||
| if ( stat.isDirectory() ) { | ||
| ulist.push('<li><a href="'+item+'/">'+item+'/</a></li>') | ||
| ulist.push('<li><a href="'+link+'/">'+item+'/</a></li>') | ||
| } else { | ||
| ulist.push('<li><a href="'+item+'">'+item+'</a></li>') | ||
| ulist.push('<li><a href="'+link+'">'+item+'</a></li>') | ||
| } | ||
@@ -134,1 +152,12 @@ cb(); | ||
| console.log('Listening ' + bindhost + ':' + bindport +' web root dir ' + dir ); | ||
| /* | ||
| var options = { | ||
| key: fs.readFileSync('./server.key'), | ||
| cert: fs.readFileSync('./server.crt'), | ||
| }; | ||
| var server = https.createServer(options, mainapp).listen(8090, function(err) { | ||
| console.log('Listening SSL port 8090 status:', err); | ||
| }); | ||
| */ |
| var express = require('express'), | ||
| path = require('path'), | ||
| url = require('url'), | ||
| fs = require('fs'), | ||
| util = require('util'), | ||
| async = require('async'), | ||
| https = require('https'), | ||
| send = require('send'); | ||
| var mainapp = express(); | ||
| // Bodyparser parses HTTP POST parameters and JSON payload | ||
| mainapp.use(express.bodyParser()); | ||
| // Logger for requests | ||
| mainapp.use(express.logger()); | ||
| var args = process.argv.slice(2); | ||
| // Serve either current or directory given as argument | ||
| var dir = process.argv[0] || process.cwd(); | ||
| dir = path.resolve( dir ); | ||
| mainapp.use(express.static( dir )); | ||
| // Add any dynamic handlers here | ||
| //mainapp.get('/ajax', function(req, res) { | ||
| // res.send('Query: ' + util.inspect(req.query)); | ||
| //}); | ||
| //mainapp.post('/test', function(req, res) { | ||
| // res.send('Parameters: ' + util.inspect(req.body)); | ||
| //}); | ||
| // Catch all function when static server did not find any file to serve. In case requested | ||
| // file matched directory, this tries to find first index.html and if that fails it builds | ||
| // the directory listing. | ||
| mainapp.get('*', function(req, res) { | ||
| var pathname = url.parse(req.url).pathname; | ||
| pathname = path.join(dir, pathname); | ||
| fs.stat(pathname, function(err, stat) { | ||
| // Check if path is directory | ||
| if ( !stat || !stat.isDirectory() ) return res.send(404); | ||
| // check for index.html | ||
| var indexpath = path.join(pathname, 'index.html'); | ||
| fs.stat(indexpath, function(err, stat) { | ||
| if ( stat && stat.isFile() ) { | ||
| // index.html was found, serve that | ||
| send(res, indexpath) | ||
| .pipe(res); | ||
| return; | ||
| } else { | ||
| // No index.html found, build directory listing | ||
| fs.readdir(pathname, function(err, list) { | ||
| if ( err ) return res.send(404); | ||
| return directoryHTML( res, req.url, pathname, list ); | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| // Reads directory content and builds HTML response | ||
| function directoryHTML( res, urldir, pathname, list ) { | ||
| var ulist = []; | ||
| function sendHTML( list ) { | ||
| res.setHeader('Content-Type', 'text/html'); | ||
| res.send('<!DOCTYPE html>' + | ||
| '<html>\n' + | ||
| '<title>Directory listing for '+urldir+'</title>\n' + | ||
| '<body>\n' + | ||
| '<h2>Directory listing for '+urldir+'</h2>\n' + | ||
| '<hr><ul>\n' + | ||
| list.join('\n') + | ||
| '</ul><hr>\n' + | ||
| '</body>\n' + | ||
| '</html>'); | ||
| } | ||
| if ( !list.length ) { | ||
| // Nothing to resolve | ||
| return sendHTML( ulist ); | ||
| } | ||
| // Check for each file if it's a directory or a file | ||
| var q = async.queue(function(item, cb) { | ||
| fs.stat(path.join(pathname, item), function(err, stat) { | ||
| if ( !stat ) cb(); | ||
| if ( stat.isDirectory() ) { | ||
| ulist.push('<li><a href="'+item+'/">'+item+'/</a></li>') | ||
| } else { | ||
| ulist.push('<li><a href="'+item+'">'+item+'</a></li>') | ||
| } | ||
| cb(); | ||
| }); | ||
| }, 4); | ||
| list.forEach(function(item) { | ||
| q.push(item); | ||
| }); | ||
| q.drain = function() { | ||
| // Finished checking files, send the response | ||
| sendHTML(ulist); | ||
| }; | ||
| } | ||
| // Fire up server | ||
| mainapp.listen(8000); | ||
| console.log('Listening port 8000 root dir ' + dir ); | ||
| var options = { | ||
| key: fs.readFileSync('./server.key'), | ||
| cert: fs.readFileSync('./server.crt'), | ||
| }; | ||
| var server = https.createServer(options, mainapp).listen(8090, function(err) { | ||
| console.log('Listening SSL port 8090 status:', err); | ||
| }); |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
28936
8.25%144
-33.94%