lwsjs / local-web-server Goto Github PK
View Code? Open in Web Editor NEWA lean, modular web server for rapid full-stack development.
License: MIT License
A lean, modular web server for rapid full-stack development.
License: MIT License
› ws
morgan deprecated morgan(options): use morgan("default", options) instead ../../../.nvm/v0.10.26/lib/node_modules/local-web-server/bin/ws.js:107:17
morgan deprecated default format: use combined format ../../../.nvm/v0.10.26/lib/node_modules/local-web-server/bin/ws.js:107:17
serving at http://localhost:8000
Is there a way to implement virtual host config?
For now, I simply add my host alias into /etc/hosts
and it proxifies me to 127.0.0.1
But in my opinion it would be nice to be able to configure it.
I looked for koa adapter and found two versions: koa-vhost and vhost-koa.
Both are developed for older koa versions.
I tried first of those, but it seems that I'm doing something wrong. The way I include it is like this:
if (options.host) {
const vhost = require('koa-vhost')
debug('host', options.host)
app.use(vhost({
host: options.host,
app: app
}))
}
im working with ext-js 6
i compile my app as development (sencha app build development) and use ws
for local js files and as a proxy to my server calls which runs on tomcat.
with every refresh of the page it becomes slower and slower.
worth to mention that ext-js has a cache buster in the URL, maybe its that.
maybe its the multiple calls.
there are 804 requests done from the browser when loading the page.
anyway its really annoying to refresh it every time, if you need further information, ill be glad to give you anything you need.
Proxy servers (e.g. Charles) have the usual ability to filter out unwanted resources (e.g. scripts) from the servers they proxy to.. Would be useful in local-web-server.
As the title says. I thought that maybe I am doing something wrong, but then I took the examples from repository (https://github.com/75lb/local-web-server/tree/master/example/mock) and the same problem occurs. PUT request to /users/1 is in fact removing the user, because there is no ctx.request.body and POST request to /users adds object with just "id" property to the users array. It's the most useful feature of mocks for me and sadly it is not working.
I've googled a bit and the problem seems to be related to Koa bodyparser. Tried to fix it myself, but I don't have enough knowledge about Koa to understand what exactly is going wrong and why.
If we have two .local-web-server.json
files, say in the current directory and in the user's $HOME
, configurations like port
get merged properly, but if both files have rewrite
rules, then only the rules in the current directory show up with ws --config
.
Maybe it needs a deep merge?
useful for devs that using daily
if my config is stored in project/package.json
and i'm in project/web
, the config from the directory above should still be loaded.
Is there a way I can bind the server to 0.0.0.0 address
with http-server, we do this -a flag
http-server -a 0.0.0.0
with webpack-dev-server we do this with --host flag
webpack-dev-server --host 0.0.0.0
This would be very useful when we deploy it inside containers
Is it possible to delay responses in some way? I tried implementing koa-slow, but no luck. Still instant response.
It would be cool to be able to implement some sort of delay for mocks. Maybe even with the use of a function, so that I can write my random delay e.g. between 50 and 1500 ms.
I'm not sure of that's out of scope for this project, maybe you have some other ideas?
Hi. I would like to use SPA mode to test my app. I my case the paths are entire URIs, for example
http://localhost:8000/http://some.uri.in.path
When I start the web server with ws -s index.html
, such requests are not rewritten. ws
logs a message saying
Not rewriting GET /http://some.uri.in.path because the path includes a dot (.) character
I understand it works under the assumption that dot signifies static content?
I tried --rewrite /* -> index.html
but this causes any request, even when static files which exist, to respond with index.html.
Running on Ubuntu 15.04. Any ideas?
roo@roo-laptop:~/Development/react/one$ ws
/usr/local/lib/node_modules/local-web-server/bin/ws.js:70
if (argv.misc.config){
^
TypeError: Cannot read property 'config' of undefined
at Object.<anonymous> (/usr/local/lib/node_modules/local-web-server/bin/ws.js:70:14)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Hey there,
Whenever I try a POST request, I get the "Method Not Allowed" message.
Have I missed something in the configuration? or is local-web-server not intended to work with POST (as SimpleHTTPServer on python?).
Apart from that, thumbs up!
err msg currently appears in Connection column, put somewhere else..
$ ws
serving at http://localhost:8000
Requests Data Connections
24 50.60 KB Error: ENAMETOOLONG, stat '/Users/Lloyd/Documents/blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah'
using the --verbose
flag you can see the URLs of proxied requests.. would like an option to see the header and body content of each proxied request too.
xxx
Hi, I'm having an issue getting a rewrite rule to successfully serve files after setting a new root directory as a SPA. Basically, my folder directory is similar to this:
Essentially, I'm launching the ws from the project root, setting app as the new root directory, setting index.html as the starting point for the SPA flag, and then trying to serve the bower_components folder to the app.
This is my launch command:
ws -d app --spa index.html -r '/bower_components/* -> ../bower_components/$1'
I'm getting a 403 error in terminal whenever the server tries to access the files. So I believe it's finding the folder, but can't serve it up. I've tried modifying the folder permissions with no success so far. Is there a way to do this currently? I might just be missing something completely. Any assistance would be greatly appreciated! Thanks!
Allow user to create, list, update, delete and run preset commands. E.g.
$ # open projects one and two on separate ports
$ ws ~/projects/one:8000 ~/projects/two:9000
$ # give this command a name, for later use
$ ws ~/projects/one:8000 ~/projects/two:9000 --name current --desc "Two shitty projects"
$ # list presets
$ ws -l
Preset List
current - Two shitty projects
$ # launch your two projects from the preset
$ ws --preset current
please leave a +1 if you think this would help
need a simple method define a mock responses.. a means of specifying, e.g. "any GET request to /api/camel
should return mock camel data but a POST returns 403".
Now if I want to run HTTPS server I need to have key and cert
Usually I do it for dev so its not big reason what cert to use
so why not create some flag which will run https without having cert and key like ws -s
like in gulp connect https://github.com/avevlad/gulp-connect#optionshttps
i.e.
$ ws ~/projects/one:8000 ~/projects/two:9000
please leave a +1 if you think this would help
As the title says, that would be very nice.
Like in the npm-server "web-server-rewrite" I really need http-rewrite-rules with regular expressions. But:
What for is this? It's especially for services which need to be rewritten to another url in local and live-environment, e.g.:
rewrites
{
"localhost": {
"(.*)(/users/)(.*)": "http://myserver1.mw.domain.lan:10080/middleware1/$3",
"(.*)(/auth/)(.*)": "http://myserver2.mw.domain.lan:10080/auth-service/$3"
},
"domain.de": {
...
}
}
This would be very helpful - and if you include the keyword "rewrite" in your descriptions, this would definitely boost your server-implementation!
Regards
Markus
... could be more useful than reams of log output..
Currently tries to download when accessing .shtml files.
I want to use Sourcegraph for local-web-server code search, browsing, and usage examples. Can an admin enable Sourcegraph for this repository? Just go to https://sourcegraph.com/github.com/75lb/local-web-server. (It should only take 30 seconds.)
Thank you!
Already scratched my head for far too long...
[22:57:00] Error: Cannot find module 'mocks\servers.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:289:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
Got this config:
lws({
'static': {
'root': './'
},
'mocks': [{
'route': '/',
'module': '/mocks/servers.js'
}]
}).listen(2650)
Happens on line 151. Basically, it's not able to load the file. However, if I remove the 'module' property, the server starts (of course), and I'm able to navigate to /mocks/servers.js
and get the content.
Seems like if I have more than one rewrite specified, I'm unable to start the server:
...\node_modules\local-web-server\node_modules\path-to-regexp\index.js:89
if (index < str.length) {
^
TypeError: Cannot read property 'length' of undefined
{
"rewrite": [
{ "from:": "/PathOne/*", "to": "http://localhost/PathOne/$1" },
{ "from:": "/PathTwo/*", "to": "http://localhost/PathTwo/$1" },
{ "from": "/PathThree/*", "to": "http://localhost/PathThree/$1" }
]
}
Let me know if any other info would help.
I'm running in single page application mode. I never see this header which is preventing api calls to my backend from working while in development mode.
The docs say this: CORS-friendly, all origins allowed by default.
making me think it should be set by default.
Furthermore, I thought there would be a way to customize headers. I can't find any documentation that shows how to add specific headers to all request responses. Is that possible?
Thanks!
Hi,
First of all thank you for making such a handy project. I was looking for such a static local web server, it works well. But it keeps downloading *.php file as if it's not in server root.
I am on Ubuntu 14.04 platform.
What should I do to let server open *.php files in browser?
Regards
Kenn
currently, ws
merges config loaded from package.json
and/or .local-web-server.json
(depending on which exists).
Implement a --config-file
(or similar) option to enable the user to specify a config file name. This would be useful for A/B testing, comparing server results using config A against config B.
The set up is like the following:
localhost:8000
localhost:8000/web_page/index.html
localhost:8000/web_page/iframe/index.html
localhost:8000/web_page/iframe/scripts/some_script.js
The HTML is:
<iframe src="iframe"></iframe>
I start the server using the following command line:
ws --spa index.html
The error I get is:
GET http://localhost:8000/iframe 404 (Not Found)
I think the expected behavior is for the relative path of the iframe src value of "iframe" to look in the subdirectory "localhost:8000/web_page/iframe" and use the spa of "index.html" as well as all the contents inside the iframe should have the relative path of the src value.
This does not seem to work with the following iframe src values:
iframe
iframe/
iframe/index.html
This does seem to work with the following iframe src values:
web_page/iframe/
/web_page/iframe/
The following partially works, but the relative path of the elements in the iframe seem to look in the parent directory, "localhost:8000/web_page", instead of "localhost:8000/web_page/iframe" (tries to serve "localhost:8000/web_page/scripts/some_script.js" instead of "localhost:8000/web_page/iframe/scripts/some_script.js").
/web_page/iframe
web_page/iframe
(Sorry if I'm doing something dumb!)
local-web-server proxy request +0ms from: /loginservice/de/1234, to: http://myserver/login/de?myId=1234
curl -v -H "Content-Type:application/json" --data "@testrequest.json" "http://mylocalhost/loginservice/de/1234"
POST /loginservice/de/1234 HTTP/1.1
User-Agent: curl/7.35.0
Host: ...
Accept: /
Content-Type:application/json
Content-Length: 122
Have an issues with running server...:
For the record, package.json looks like in a sample:
{
"name": "web-sever",
"version": "1.0.0",
"scripts": {
"start": "ws"
}
}
When I trying to run in terminal, here what I get:
local-user-mac:ws local-user$ npm start
> web-sever@1.0.0 start /Users/local-user/work/ws
> ws
sh: ws: command not found
npm ERR! Darwin 13.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code ELIFECYCLE
npm ERR! web-sever@1.0.0 start: `ws`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the web-sever@1.0.0 start script 'ws'.
npm ERR! This is most likely a problem with the web-sever package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ws
npm ERR! You can get their info via:
npm ERR! npm owner ls web-sever
npm ERR! There is likely additional logging output above.
It is possible to deny serving different file types?
When sending a post body, the proxy doesnt work.
for example:
$.ajax({
type: 'post',
data: {"someKey": "someValue"}
...
})
When tried to access the test page in my mobile. A popup shows with the message
Authentication Required
The server at http://xxx.xx.x.x:80 requires a user name and password.
The server says level_15 or view_access
What to change in configuration setting to avoid this login?
maybe something looking like:
Open connections | Active clients | Requests | Transferred |
---|---|---|---|
6 | 1 | 30 | 43.4kb |
Resource | Downloads | Total Transferred |
---|---|---|
/index/html | 13 | 32kb |
/js/app/js | 3 | 600kb |
/img/car.png | 20 | 4.3mb |
Type | Downloads | Transferred |
---|---|---|
.html | 34 | 300kb |
.jpg | 323 | 3.2mb |
.js | 16 | 1.1mb |
Hi,
Awesome tool! Just one question - I am using Browser Sync and it seems to go into an endless refresh loop when hosting through the local-web-server. Is there a way around it? OR rather, is it possible to support rerouting of the ws:// protocol?
Thanks,
Johann
Starting with v0.5.20
, it's not possible to disable console logging.
$ ws --log-format none
/Users/adam/.nvm/versions/node/v0.12.4/lib/node_modules/local-web-server/node_modules/connect/index.js:87
if (typeof handle.handle === 'function') {
^
TypeError: Cannot read property 'handle' of undefined
at Function.use (/Users/adam/.nvm/versions/node/v0.12.4/lib/node_modules/local-web-server/node_modules/connect/index.js:87:20)
at launchServer (/Users/adam/.nvm/versions/node/v0.12.4/lib/node_modules/local-web-server/bin/ws.js:113:9)
at Object.<anonymous> (/Users/adam/.nvm/versions/node/v0.12.4/lib/node_modules/local-web-server/bin/ws.js:88:5)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
All other logging modes seem to work fine.
are there are benefits to switching from Connect to Koa?
if a remote proxy request fails for some reason (e.g. socket hang-up), ws
crashes.. it should handle the exception, report the issue and carry on.
InternalServerError: [PROXY] socket hang up: http://lhtapp01:8180/resources/contents/copies/113864/draft?nocache=146315555730825777655849.375153
at Object.throw (/Users/lloydb/Documents/75lb/local-web-server/node_modules/koa/lib/context.js:91:23)
at ProxyServer.proxy.once.err (/Users/lloydb/Documents/75lb/local-web-server/lib/middleware.js:40:17)
at ProxyServer.emit (/Users/lloydb/Documents/75lb/local-web-server/node_modules/eventemitter3/index.js:144:27)
at ClientRequest.proxyError (/Users/lloydb/Documents/75lb/local-web-server/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:141:16)
at emitOne (events.js:101:20)
at ClientRequest.emit (events.js:188:7)
at Socket.socketCloseListener (_http_client.js:282:9)
at emitOne (events.js:101:20)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:4ecc-ui lloydb:$
npm start
Hello, I am trying to handle POST requests. I have probably done something wrong but I can not debug the Error. I receive "Internal Server Error" but there is no other info. I can not detect any log file. Any help, suggestion?
IMHO alpha versions shouldn't install when using npm without version specifier.
Hello!
Is it possible to proxy request HTTP headers? For instance, it would be great if I could send basic authentication header to test front-end with a real REST API. Adding login and password to URL in plain text does not work.
Thanks for any information.
Kind regards,
Vladimir
for example, how you would do it express
app.use("/assets", serveStatic("./app/assets"));
app.use("/css", serveStatic("./cheese/css"));
etc.
.. in a similar NPM does with the "config" hash in package.json
Is there some reason it's not on my default? It adds negligible CPU load and is far and away a "best practice". Just found this after using http-server (which doesn't even offer the option to compress) and really like things so far (--spa
rocks) but would be nice to avoid typing -c
every time.
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.