nbluis / static-server Goto Github PK
View Code? Open in Web Editor NEWA simple static server written in node.js
A simple static server written in node.js
$ mkdir ~/test/ && cd ~/test/
$ jspm init
$ ln -s jspm_packages/system.js system.js
$ touch index.html
<!-- index.html -->
<html>
<body>
<script src="system.js"></script>
<script src="config.js"></script>
</body>
</html>
$ static-server --follow-symlink
Crashes on navigating to index.html
:
$ static-server --follow-symlink
* Static server successfully started.
* Serving files at: http://localhost:9080
* Press Ctrl+C to shutdown.
<-- [GET] /
--> 200 OK / (index.html) 190 Byte (10.451ms)
<-- [GET] /system.js
<-- [GET] /config.js
* Shutting down server
path.js:8
throw new TypeError('Path must be a string. Received ' +
^
TypeError: Path must be a string. Received undefined
at assertPath (path.js:8:11)
at Object.posix.relative (path.js:496:3)
at StaticServer.<anonymous> (/usr/local/lib/node_modules/static-server/bin/static-server.js:55:115)
at emitOne (events.js:90:13)
at StaticServer.emit (events.js:182:7)
at /usr/local/lib/node_modules/static-server/server.js:249:22
at FSReqWrap.oncomplete (fs.js:82:15)
For the rootPath to have a value, I have to concatenate the same value to notFound
If I configure the server like the following, it will return 403 forbidden's because the path will not be accessible.
{
rootPath: './build',
templates: {
index: 'index.html',
notFound: 'index.html'
}
}
I have to configure it like so for it to work:
{
rootPath: './build',
templates: {
index: 'index.html',
notFound: 'build/index.html'
}
}
See if node-static can be integrated. Related to issues #4, #6, and #8.
Hi,
How can I use the optional browser like Phantom.js? Can you please let me know.
Thanks.
Upgrade dependencies to version 3.0 and Nodejs 5.
I have this right now:
const k = cp.spawn('bash',[], {
env: Object.assign({}, process.env, {FORCE_COLOR:1})
});
k.stdin.end(`static-server`);
but colors are not showing up in the terminal...
NVM, I solved the issue with this solution
http://derpturkey.com/retain-tty-when-using-child_proces-spawn/
that solution is more elegant and generic than using some random env var
Some browsers (IE9+ baiscally) retricts the rendered content based on their content type.
Basically we must identify the mime type of a file (can be based on extension at now) and write the header.
Steps do reproduce:
Problem:
The program tries to serve the index.html file, but the file does not exist and an error occurs (http 500).
Expectation:
Should just send a 404 error like requests to a unexisting files.
It would be nice to be able to serve clean URLs for static sites. For example, an HTML file without the .html extension is treated like an octet-string content type. This prompts the browser to download the file instead of loading it as html.
can we add sserver
cli-shortcut? it’s easier to type, and can be easily autocompleted.
This is my echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
In my laptop, I use -c *
and everything works ok, but in my cloud server, I use the same command line, the Access-Control-Allow-Origin in response headers is wrong.
My cloud server system is Ubuntu, and node version is 8.11.1, npm version 5.6.0
Directory listing (like apache) is a good feature sometimes we have a directory with a lot of files.
When asked for a directory, instead of opening the default file (index.html), list all files and directories within it.
I think a html page to link each entry is a good idea.
PS: Just to be safe, should only be enabled via parameter not by default.
When the server receives invalid Range, it crashes with the following error:
res.headers['Content-Range'] = 'bytes=0-' + originalSize;
^
ReferenceError: res is not defined
at parseRanges (C:\Users\JP\AppData\Roaming\npm\node_modules\static-server\server.js:364:9)
at sendFile (C:\Users\JP\AppData\Roaming\npm\node_modules\static-server\server.js:446:22)
at C:\Users\JP\AppData\Roaming\npm\node_modules\static-server\server.js:169:9
at C:\Users\JP\AppData\Roaming\npm\node_modules\static-server\server.js:275:9
at FSReqWrap.oncomplete (fs.js:95:15)
It seems like the function for parsing ranges isn't passed the res
variable.
Would you be willing to accept a PR for a flag that will suppress the output of what URLs being fetched?
I'm working with some new file formats and descovered there's no way to quickly add a new mime type to the server. If there was a file to augment or override the existing mime types from the mime module I think it would be really useful.
Happy to do the work if you want to tell me how you'd like to see it done.
Thanks!
... and drop support for Node 0.10, 0.11, and 0.12.
let
and const
and all compatible ES5/6 commonly implemented featuresPromise
instead of callbacks to support future async/await
Prevent URI from going above the root path. Paths like /../
, or /some/dir/../../../../index
should be forbidden; basically, resolve the URI path and if a string /../
is found, reject it.
would be nice for local developments to force no-cache/expired headers on all files. right now my mobile phone caches the resources to aggressively
Please, upgrade to streams when serving files, this will not only reduce the memory footprint, but will make things even faster!
Node: 9.4
server.on('request', function (req, res) {
// req.path is the URL resource (file name) from server.rootPath
// req.elapsedTime returns a string of the request's elapsed time
});
In this case res
is null, so you can't modify f.e headers (I needed to add MIME)
For new node version I suggest node-static
I suggest to just write compatible node versions to readme
although it's pretty easy to write a wrapper to listen on any 0.0.0.0
or a particular host ip address, but the CLI is used for convenience, why not provide it in default?
-h, --help output usage information
-V, --version output the version number
-p, --port <n> the port to listen to for incoming HTTP connections
--host <host-ip> the host ip address to listen on, can be `0.0.0.0` for any
-i, --index <filename> the default index file if not specified
-f, --follow-symlink follow links, otherwise fail with file not found
-d, --debug enable to show error messages
-n, --not-found <filename> the error 404 file
comparing python -m SimpleHTTPServer
by default listen on 0.0.0.0
; and python3 provides an option
➸ python3 -m http.server --help
usage: server.py [-h] [--cgi] [--bind ADDRESS] [port]
positional arguments:
port Specify alternate port [default: 8000]
optional arguments:
-h, --help show this help message and exit
--cgi Run as CGI Server
--bind ADDRESS, -b ADDRESS
Specify alternate bind address [default: all
interfaces]
I succeeded to start static-http-server in Windows 10 Linux subsystem Ubuntu 18.06 with fresh- installed nodejs 12.3.1 Server starts and displays port list
Expected: since I'm in IPV6 network both at home and at office, I expect local IPV6 address [::1] like in PING localhost(localhost (::1)) 56 data bytes
Actual: list of irrelevant IPV4 addresses.
Proposed solution: Nodejs supports IPV6 Please, correct static-http-server according nodejs documentation
Chrome and Edge default on Windows 10 is IPV6
This always shows when running bin/static-server.js
:
options.index is now deprecated please use options.templates.index instead.
A possible fix would be to add program.index = undefined;
after:
static-server/bin/static-server.js
Line 44 in ab1ca09
Since program
(command line options object) is passed as options
to the constructor.
Please cover the code with unit tests.
Win7 Pro 64bit
Node: v6.0.0
static-server: ^2.0.3
Just hit a bout of confusion with the sample source from the README.md file regarding server.on('response'...
. The callback arguments for file
and stat
are in switched.
// README.md docs...
server.on('response', function (req, res, err, stat, file) {
console.log(file); // [Object object] <-- stat object
console.log(stat); // '/path/to/file/in/question' <-- file string
}
I'll submit a PR for this, but just curious if there was a design change in the response callback implementation that caused this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.