简体   繁体   English

客户端还是服务器端框架?

[英]Client-side or server-side framework?

My project would be a kind of craiglist, a site where users could post anouncements (evereday-life objects, cars, flat etc.). 我的项目将是一个craiglist,一个用户可以在其中发布公告(无所事事的物体,汽车,公寓等)的网站。 So, authentication, profile page, content creation, display the for-sale objects etc. 因此,身份验证,配置文件页面,内容创建,显示待售对象等。

I have developed a very large part of the backend: I have a RESTful API in three-tier architecture developed in java. 我已经开发了很大一部分后端:我有一个用Java开发的三层体系结构的RESTful API。 It makes the link with the db, to provide me with different urls and send me the relevant JSON. 它与数据库建立链接,为我提供不同的URL并向我发送相关的JSON。

URLs example: 网址示例:

http://api.mywebsite.fr/user?userid=1 sends me back: http://api.mywebsite.fr/user?userid=1将我发送回去:

{"user": {"username": "jdoe1234", "email", "jdoe1234@gmail.com"}}

I have urls for all actions performed on the entire site (anouncement creation, last data updates ... everything, and I've carefully declared them POST, GET, UPDATE, DELETE, etc.). 我具有在整个网站上执行的所有操作的网址(公告创建,最近的数据更新……所有内容,我已经将它们声明为POST,GET,UPDATE,DELETE等)。 There is also oAuth to protect the API from queries that are not allowed for the token. 还有oAuth可以保护API免受令牌不允许的查询。

That's all for the "server" aspect, I think that there is no problem with that. 这就是“服务器”方面的全部内容,我认为这没有问题。

But if all the actions are managed by the webservice, I do not see the interest that could bring me a big server-side framework like Symfony/cakePHP, Zend, etc., to make HTTP requests on my different entry points, retrieve JSON and populate the HTML. 但是,如果所有操作都由Web服务管理,那么我看不到有什么兴趣可以带给我一个大型服务器端框架,例如Symfony / cakePHP,Zend等,以便在我的不同入口点上发出HTTP请求,检索JSON和填充HTML。

So I looked at client framework, like Angular, Ember and so on. 因此,我研究了客户端框架,例如Angular,Ember等。 At first, it seemed very suitable for my case: possibility of http requests, manage what to do in case of success or error, directly exploit the resulting JSON to populate the view etc. 一开始,这似乎非常适合我的情况:http请求的可能性,管理成功或错误时的操作,直接利用生成的JSON填充视图等。

I didn't even manage to make my choice between angularjs and Ember, both being very similar, but with the release of Angular v2, I fear the maintainability of v1 (if I choose Angular, it will be v1 , because the majority of tutorials and questions relate to Angular 1.X). 我什至没有设法在angularjs和Ember之间做出选择,尽管两者非常相似,但是随着Angular v2的发布,我担心v1的可维护性(如果我选择Angular,它将是v1,因为大多数教程和有关Angular 1.X的问题。

I don't know if I'm doing the right thing by choosing client-side framework, I am afraid that they 'brident' (not sure of that word, sorry) me. 我不知道我是否通过选择客户端框架来做正确的事,恐怕他们对我“盲目”(不确定这个词,对不起)。 Plus, it's fully instantiated in the browser, so the user can change absolutely all code and data I provide. 另外,它在浏览器中已完全实例化,因此用户可以更改我提供的所有代码和数据。 That seems weird to me. 在我看来这很奇怪。

I want to be absolutely sure of the technology that I use in case I make this application available to the public for example. 我想绝对确定所使用的技术,以防万一我将此应用程序向公众开放。 I want to do things properly, in order to avoid maintainability or security problems. 我想正确地做事,以避免可维护性或安全性问题。

Summary: With the things I already have (webservice / api), is it a good idea to use a client framework like Angular or should I stay on big server-side framework like Symfony/Zend etc? 简介:对于已经拥有的东西(webservice / api),使用像Angular这样的客户端框架是一个好主意还是应该留在像Symfony / Zend这样的大型服务器端框架上? Knowing that I position myself in the context in which this platform would be massively used (craiglist comparable traffic). 知道我将自己定位在该平台将被大量使用的环境中(craiglist可比流量)。

I'd say - depends whether you want to be more frontend guy or backend guy in future. 我会说-取决于您是将来想成为前端人员还是后端人员。 If you want to be full stack developer then it doesn't apply. 如果您想成为全栈开发人员,那么它就不适用。

In my opinion, both Symfony/Zend or other big server-side frameworks aren't so exciting as dynamic frontend JavaScript frameworks like Ember/Angular/React. 我认为,Symfony / Zend或其他大型服务器端框架都没有像Ember / Angular / React之类的动态前端JavaScript框架那么令人兴奋。

Also, if you have already RESTful API and OAuth authentication implemented in backend part I'd go with Ember. 另外,如果您已经在后端部分实现了RESTful API和OAuth身份验证,则可以使用Ember。 Why? 为什么? Ember Data is great tool for talking to backend API. Ember Data是与后端API通讯的绝佳工具。 It's mature, it lazily loads records when they're needed and it's very customizable. 它很成熟,可以在需要时懒惰地加载记录,并且可以非常自定义。

it's fully instantiated in the browser,so the user can change absolutely all code and data I provide... 它已在浏览器中完全实例化,因此用户可以绝对更改我提供的所有代码和数据...

Ember has built in security like sanitizing data which is rendered in it's templating language - HTMLBars. Ember内置了安全性,例如清理以模板语言HTMLBars呈现的数据。 Also, there's CORS and content security policy (CSP) standard which is implemented in Ember. 此外,还有在Ember中实施的CORS和内容安全策略(CSP)标准。

I want to be absolutely sure of the technology that I use in case I make this application available to the public for example. 我想绝对确定所使用的技术,以防万一我将此应用程序向公众开放。 I want to do things properly, in order to avoid maintainability or security problems . 我想正确地做事,以避免可维护性或安全性问题。

In Ember you can create mature, secure, production-ready applications, but you need to comfortable with your Ember skills to some degree to build such ambitious web application, but it's part of building every application. 在Ember中,您可以创建成熟,安全,可用于生产环境的应用程序,但是您需要在某种程度上熟悉Ember的技能,才能构建如此雄心勃勃的Web应用程序,但这是构建每个应用程序的一部分。

With the things that i already have(webservice / api), is it a good idea to use a client framework like Angular? 有了我已经拥有的东西(webservice / api),使用像Angular这样的客户端框架是一个好主意吗?

Yes, it's very popular solution to use MEAN stack or go with Ember + RESTful API. 是的,它是使用MEAN堆栈或与Ember + RESTful API一起使用的非常流行的解决方案。

Why should I choose Ember instead of Angular (which have a larger community/tutorials/answered questions) ? 为什么我应该选择Ember而不是Angular(社区/教程/回答的问题较大)?

Angular has larger community/tutorials/answered questions, but when I started some side project with Angular to learn its possible advantages over Ember, I was surprised how there was no consensus in it's community for doing one thing. Angular的社区/教程/回答的问题更大,但是当我与Angular开始一些附带项目以了解其在Ember之上的可能优势时,我感到惊讶的是,在社区中做一件事情没有达成共识。 So, instead of fast search how to declare and use directives (I think it was the thing that confused me) I have to do another research which way is the best. 因此,除了快速搜索如何声明和使用指令(我认为这是令我困惑的事情)之外,我还必须进行另一项研究,即最好的方法。 Also, there are lots of ways to setup project (where to put custom directives, different Angular objects) and you have to do another research which one to choose. 另外,有很多方法可以设置项目(在哪里放置自定义指令,不同的Angular对象),您必须进行另一项研究才能选择。 I ended up using repo healthy-gulp-angular as my template, but you can see it hasn't been updated for 8 months, but I think during these 8 months Angular had a lot of changes and I'm not sure if this repo is the best choice. 我最终使用repo health -gulp-angular作为模板,但是您可以看到它已经8个月没有更新,但是我认为Angular在这8个月中有很多更改,因此我不确定此repo是否是最好的选择。

In Ember you have Ember CLI tool which is built with Convention over Configuration principle. 在Ember中,您具有Ember CLI工具,该工具是根据“约定优于配置”原理构建的。 You have also Ember Data which utilizes JSON API standard - if you don't have JSON API compliant server side right now, you can write custom adapter to normalize server responses or change how backend replies. 您还拥有使用JSON API标准的 Ember Data-如果您现在没有符合JSON API的服务器端,则可以编写自定义适配器以标准化服务器响应或更改后端响应的方式。 In Ember you don't have all that headache and different best solutions to do 1 basic thing depending who you ask. 在Ember中,您并没有那么头疼,也没有不同的最佳解决方案来根据您的要求做一件基本的事情。

What means "Single page application" ? 什么是“单页应用程序”?

Single-page application is basically a page which doesn't have to reload all assets and HTML when you navigate. 单页应用程序基本上是一个页面,浏览时不必重新加载所有资产和HTML。 It's advantage over PHP - when user moves to another location he downloads only new data for that route. 与PHP相比,这是一个优势-当用户移动到另一个位置时,他仅下载该路由的新数据。 More info here. 更多信息在这里。

Does those frameworks allow me to create real routes ? 这些框架是否允许我创建真实的路线? ( www.myapp/profil/userid etc ) (www.myapp / profil / userid等)

Yes, of course. 当然是。 You don't even need # in your URL. 您甚至不需要在URL中输入# With simple rewrite rule and small amount of logic for profile route and specified path profile/:userid , when user will open URL www.myapp/profile/userid he will be automatically taken to profile route, and userid would be interpreted as route parameter, so you can take this userid and find user record from the store in model hook. 借助简单的重写规则和profile路由和指定路径profile/:userid少量逻辑,当用户打开URL www.myapp/profile/userid他将自动进入profile路由,而userid将被解释为route参数,因此您可以使用此userid并从model钩子中的商店中查找用户记录。

Client = speed, Server = stability 客户端=速度,服务器=稳定性

JS frameworks updates once per week Non-Js back-end once per year JS框架每周更新一次非Js后端每年进行一次

Client side depends to behavior depending on browser Back is related only on machine but not on environment 客户端取决于行为,具体取决于浏览器。Back仅与机器相关,与环境无关

I chose FE coz I tired to debug code by writing variables values to database to actually see what is going on in controllers -_- 我选择了FE coz,我厌倦了通过将变量值写入数据库以实际查看控制器中正在发生什么的情况来调试代码-_-

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

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