服务器端和胖客户端Web应用程序的文件夹结构 [英] Folder structure for both server side and thick client web app
问题描述
目前,我正在使用Node.js作为客户端的后台和extj或骨干网,而现在我完全对文件夹结构感到困惑。
Currently I am using Node.js for the backend and either extjs or backbone for the client and I am now completely confused on the folder structure.
使用 express
我的文件夹结构如下
Using express
my folder structure is as follow
appname
|--controllers
|--models
| |--appmodel.js
|--public
| |--css
| |--js // any client-side javascripts
|--routes
| |--router.js
|--views
| |--appview.ejs
|--app.js
其中 app.js
是入口点,它使用 router.js
来处理视图的路由和呈现。如果只是服务器端开发,这个工作正常。现在如果我想为客户端使用ExtJS或Backbone,我应该如何组织我的代码?我应该将它添加到 public
文件夹或视图
?
where app.js
is the point of entry and it uses router.js
to handle routing and rendering of the views. This works fine if it is only server-side development. Now if I want to use ExtJS or Backbone for the client, how should I organize my code? Should I add it to public
folder or views
?
appname
|--controllers
| |--extbasedcontroller.js // correct location?
|--models
| |--appmodel.js
| |--extbasedmodels.js // correct location?
|--public
| |--css
| |--js
| | |--extjs // extjs files
|--routes
| |--router.js
|--views
| |--appview.ejs
| |--extbasedview.ejs // correct location?
|--app.js
如果是这样,我应该把我的extjs文件的模型?如果我把它放在型号
文件夹中,感觉就像我在一个文件夹中混合客户端和服务器代码,这将会令人困惑...
If this is the case, where should I put the model for my extjs files? If I put it in models
folder it feels like I'm mixing up client and server code in one folder and it's going to be confusing...
推荐答案
在你的位置,我会这样做:
In your place, I would do that way:
appname
|--ServerCode
| |--controllers
| |--models
| | |--appmodel.js
| |--routes
| | |--router.js
| |--views
| | |--appview.ejs
| |--app.js
|--public
| |--css
| |--js // any client-side javascripts
| |--models
| |--controllers
| |--...
主要的想法是将公用文件夹放在范围之外的服务器javascript 文件。
The main idea is to place public folder outside of the scope of your server javascript files.
看到一个例子: https://github.com/madhums/node-express-mongoose-demo/
这篇关于服务器端和胖客户端Web应用程序的文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!