服务器端和胖客户端 Web 应用程序的文件夹结构 [英] Folder structure for both server side and thick client web app

查看:28
本文介绍了服务器端和胖客户端 Web 应用程序的文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我使用 Node.js 作为后端,使用 extjs 或主干作为客户端,我现在对文件夹结构完全困惑.

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 文件夹还是 views ?

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 文件的模型放在哪里?如果我将它放在 models 文件夹中,感觉就像我将客户端和服务器代码混合在一个文件夹中,这会令人困惑...

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...

推荐答案

代替你,我会这样做:

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屋!

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