Javascript 网络服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4230706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript web server?
提问by skyeagle
Is it possible to build a micro (proof of concept) web server in Javascript?
是否可以在 Javascript 中构建微型(概念证明)Web 服务器?
Has anyone done this before?.
有没有人以前做过这个?。
EDIT:Apparently explicit clarification is needed here. The question is ultimately about how to push data from the server to the browser after the initial request made by the browser has been closed. In other words, how to make the browser accept subsequent requests initiated by a server.
编辑:显然这里需要明确的澄清。问题最终是关于在浏览器发出的初始请求关闭后如何将数据从服务器推送到浏览器。换句话说,如何让浏览器接受服务器发起的后续请求。
Does a javascript based web server need to be installed into the browser, or is there some other method?
是否需要在浏览器中安装基于 javascript 的 Web 服务器,还是有其他方法?
采纳答案by user113716
If you're saying that you want to be able to push data to browsers that have initiated contact with your server, I'd do some research on Comet servers.
如果您说您希望能够将数据推送到已与您的服务器建立联系的浏览器,我会对 Comet 服务器进行一些研究。
I don't know anything about it, so I'll just pass off a couple links to you that will hopefully point you in the right direction.
我对此一无所知,因此我将向您传递几个链接,希望它们能为您指明正确的方向。
From Wikipedia Comet_(programming)
Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it.1Comet is an umbrella term, encompassing multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as JavaScript, rather than on non-default plugins. The Comet approach differs from the original model of the web, in which a browser requests a complete web page at a time.[3]
Comet 是一种 Web 应用程序模型,其中长期持有的 HTTP 请求允许 Web 服务器将数据推送到浏览器,而无需浏览器明确请求它。1Comet 是一个总称,包含实现这种交互的多种技术。所有这些方法都依赖于浏览器中默认包含的功能,例如 JavaScript,而不是非默认插件。Comet 方法不同于 Web 的原始模型,其中浏览器一次请求一个完整的网页。 [3]
Here's something called APE. I don't know a thing about it, but you may find it helpful.
这是一种叫做 APE 的东西。我对此一无所知,但您可能会发现它很有帮助。
APE is a full-featured OpenSource solution designed for Ajax Push. It includes a comet server and a Javascript Framework. APE allows to implement any kind of real-time data streaming to a web browser, without having to install anything on the client-side.
APE 是专为 Ajax Push 设计的全功能开源解决方案。它包括一个彗星服务器和一个 Javascript 框架。APE 允许将任何类型的实时数据流传输到 Web 浏览器,而无需在客户端安装任何东西。
回答by Pointy
Check out the RingoJS project, or Node.js. The answer is "yes", and not just "micro" or "proof of concept".
查看 RingoJS 项目或 Node.js。答案是“是”,而不仅仅是“微观”或“概念证明”。
回答by PleaseStand
There's an add-on for Firefox (also available as a separate desktop application) called Plain Old Webserver. It's supposed to be able to run a special kind of server-side JavaScript that has access to all the internal features of the web browser, including local file and SQLite database access, access to browser preferences and history, and anything else that can be done with a Firefox add-on.
Firefox 有一个附加组件(也可作为单独的桌面应用程序使用),称为Plain Old Webserver。它应该能够运行一种特殊的服务器端 JavaScript,它可以访问 Web 浏览器的所有内部功能,包括本地文件和 SQLite 数据库访问、对浏览器首选项和历史记录的访问,以及任何其他可以完成的事情使用 Firefox 插件。
回答by CStumph
Have you seen Juggernaut? https://github.com/maccman/juggernaut/blob/master/README.mdYou'll have to forgive, I'm not sure if this exactly what you are looking for, and am a bit of a noob, but the readme made it sound like good fit for what you're describing.
你见过剑圣吗? https://github.com/maccman/juggernaut/blob/master/README.md你必须原谅,我不确定这是否正是你要找的,我有点菜鸟,但是自述文件使它听起来很适合您所描述的内容。
回答by Jon Winstanley
JS HTTPD
JS HTTPD
http://acme.com/software/js_httpd/
http://acme.com/software/js_httpd/
Is a small UNIX HTTP server written in JavaScript.
是一个用 JavaScript 编写的小型 UNIX HTTP 服务器。
It runs from inetd, which means its performance is poor. But for low-traffic sites, it's quite adequate. It implements all the basic features of an HTTP server, including:
它从inetd运行,这意味着它的性能很差。但是对于低流量的网站来说,已经足够了。它实现了 HTTP 服务器的所有基本功能,包括:
- Security against ".." filename snooping.
- The common MIME types.
- Trailing-slash redirection.
- index.html
- Directory listings.
- 防止“..”文件名窥探的安全性。
- 常见的 MIME 类型。
- 尾随斜线重定向。
- 索引.html
- 目录列表。
js_httpd can also be used to serve HTTPS by wrapping it with stunnel. Instructions are included.
js_httpd 也可以通过用 stunnel 包装来提供 HTTPS。包括说明。
Other tiny and/or weird web servers (all run from inetd):
其他小型和/或奇怪的 Web 服务器(都从 inetd 运行):
回答by Panait Valentin
You could try "ewsjs is an embedded Web server inside your browser. When developing Ajax-based and single-page-applications, it is often very difficult to test these applications until a Web server is in place. (...)
您可以尝试“ewsjs 是浏览器中的嵌入式 Web 服务器。在开发基于 Ajax 的单页应用程序时,通常很难测试这些应用程序,直到 Web 服务器就位。(...)
EWS provides an embedded Web server that looks to your Ajax application as if it is coming from the server. You can put in any logic and fully test out your Ajax application within the browser, without running a server.
EWS 提供了一个嵌入式 Web 服务器,它查看您的 Ajax 应用程序,就好像它来自服务器一样。您可以放入任何逻辑并在浏览器中完全测试您的 Ajax 应用程序,而无需运行服务器。
EWS supports several key features: Registering handlers for any path, Registering handlers for parametrized paths (like Sinatra routes), Registering a handler for automatic (when no other handler matches), Rewriting of one path to another (like in Apache or nginx), Asynchronous (exactly mimicking true ajax calls)"
EWS 支持几个关键功能:为任何路径注册处理程序,为参数化路径注册处理程序(如 Sinatra 路由),为自动注册处理程序(当没有其他处理程序匹配时),将一个路径重写为另一个(如在 Apache 或 nginx 中),异步(完全模仿真正的ajax调用)”