简体   繁体   English

创建一个单页Web应用程序作为网站的一部分

[英]Creating a single page web app as part of a website

I am working on a project which allows users to monitor energy consumption. 我正在做一个允许用户监视能耗的项目。 The main dashboard page is a web app which is pretty neat and makes extensive use of javascript and ajax. 仪表板主页面是一个非常整洁的Web应用程序,它广泛使用了javascript和ajax。 The server currently runs apache and uses php; 服务器当前运行apache并使用php; however, I am planning on installing node.js and updating the server side scripts in order to support websockets (and I also like the idea of using javascript on the server and client side). 但是,我计划安装node.js并更新服务器端脚本以支持websocket(并且我也喜欢在服务器端和客户端使用javascript的想法)。

I have followed several online introductions but I am struggling to find answers to specific questions, one of which is outlined below. 我已经关注了几个在线介绍,但是我一直在努力寻找特定问题的答案,下面概述其中一个。

All guides to node seem to only support single page web apps. 所有节点指南仅支持单页Web应用程序。 This is an issue as there are a number of different pages which require files to be served. 这是一个问题,因为有许多不同的页面需要提供文件。 How can I support file serving but enable one of the pages to use websockets. 我如何支持文件服务,但要使其中一个页面能够使用websocket。 Does this functionality, which is only required for one page, need to be coded into the main server script on the site or is there a way of separating this so that the server goes to server the dashboard html file and then discovers that the file requires specific websocket dependencies? 是否只需要将此功能用于一页,就需要将其编码到站点上的主服务器脚本中,还是可以通过某种方式将其分开,以便服务器将服务器的仪表板html文件发送到服务器,然后发现该文件需要具体的websocket依赖关系?

Thank you very much for taking the time to read my questions. 非常感谢您抽出宝贵的时间阅读我的问题。 If you can answer any of them, or even provide any general advice, it would be greatly appreciated. 如果您可以回答其中任何一个,甚至提供任何一般性建议,我们将不胜感激。

1: The only reason the guides do single page web apps is because that's node's forte. 1:指南做单页Web应用程序的唯一原因是节点的优势。 Node.js serves static files and rendered templates just fine. Node.js可以很好地提供静态文件和呈现的模板。 Just include the JS for the websockets only in the pages that need it. 仅将websocket的JS仅包含在需要它的页面中。

2: It's not quite as simple as with php, but take a look at express.js 2:这不像使用php那样简单,但请看一下express.js

3: Yes, and really you shouldn't even need different ports, you can write a proxy in node in one line. 3:是的,实际上您甚至不需要其他端口,您可以在一行中的节点中编写代理。

4: CentOS is fine, node is platform agnostic. 4:CentOS很好,节点与平台无关。 All the linuxes have top support followed by osx, solaris and windows. 所有linux都具有顶级支持,其次是osx,solaris和Windows。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM