创建单页 Web 应用程序作为网站的一部分 [英] Creating a single page web app as part of a website

查看:48
本文介绍了创建单页 Web 应用程序作为网站的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个项目,该项目允许用户监控能源消耗.主仪表板页面是一个非常简洁的 Web 应用程序,并广泛使用了 javascript 和 ajax.服务器目前运行apache,使用php;但是,我计划安装 node.js 并更新服务器端脚本以支持 websockets(我也喜欢在服务器端和客户端使用 javascript 的想法).

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. The server currently runs apache and uses 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).

我已经关注了几个在线介绍,但我正在努力寻找特定问题的答案,下面概述了其中之一.

I have followed several online introductions but I am struggling to find answers to specific questions, one of which is outlined below.

所有 node 指南似乎只支持单页 web 应用程序.这是一个问题,因为有许多不同的页面需要提供文件.我如何支持文件服务但启用其中一个页面以使用 websockets.此功能是否只需要一个页面,是否需要编码到站点上的主服务器脚本中,或者是否有办法将其分开,以便服务器转到仪表板 html 文件的服务器,然后发现该文件需要特定的 websocket 依赖项?

All guides to node seem to only support single page web apps. 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. 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?

非常感谢您花时间阅读我的问题.如果您能回答其中任何一个问题,甚至提供任何一般性建议,我们将不胜感激.

推荐答案

1:指南制作单页 Web 应用程序的唯一原因是因为这是 node 的强项.Node.js 提供静态文件和渲染模板就好了.只需在需要它的页面中包含 websockets 的 JS.

1: The only reason the guides do single page web apps is because that's node's forte. Node.js serves static files and rendered templates just fine. Just include the JS for the websockets only in the pages that need it.

2: 不像用php那么简单,但是看看express.js

2: It's not quite as simple as with php, but take a look at express.js

3:是的,实际上你甚至不需要不同的端口,你可以在一行中在 node 中编写一个代理.

3: Yes, and really you shouldn't even need different ports, you can write a proxy in node in one line.

4:CentOS 很好,节点与平台无关.所有的 linux 都有顶级支持,其次是 osx、solaris 和 windows.

4: CentOS is fine, node is platform agnostic. All the linuxes have top support followed by osx, solaris and windows.

这篇关于创建单页 Web 应用程序作为网站的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆