Table of Contents
回复内容:
Home Backend Development PHP Tutorial 目前来说在网站架构方面采用nobackend这种方案构建是否真的可行?

目前来说在网站架构方面采用nobackend这种方案构建是否真的可行?

Jun 06, 2016 pm 04:45 PM
android api session token web

就是说 web,ios,android只是个展示层,持久化操作统一丢给api。
先不考虑 模板渲染这一块,我们可能会把这块放到前端。
目前纠结就是 web的session 和 app的token 问题。
这套api不单单通过token来校验,而是当web请求是他是会有用户session的。
当含有用户session的时候就不用校验token。
这种做法有什么局限性或者缺点吗?
欢迎指正拍砖!
后端php..

回复内容:

当然可行,而且我还有很多成功案例,业内的案例应该也不少,尽管有些是忽悠人的,有些只是看起来是那么回事儿,实际却不是。

但是话说回来,这事儿还是看你们有没有资深架构师,要真的有很多钱的话,我不介意用.NET给你们证明这个架构的可行性的。(PHP无爱抱歉)


如果你真的纠结token和session这种问题,要么是因为你们没有能力搞定这个架构,要么是你没玩过心里没底,我不太知道是哪一种,总之是否可行的答案是肯定的。 我理解你说的nobackend是指不想采取PHP、JSP之类技术的传统架构,那类架构在session里会放一堆用户业务的状态,并在服务器端写逻辑来更新页面或者操作后端服务(如,更新数据库)。

就我个人经验而言,你完全可以把页面更新和用户当前状态放在前端,后端API是一组无状态的服务,这其实是很常见的架构了。

比较麻烦的(从你的问题描述里也可以看出)是安全那块。

native的client,你可以考虑oauth implicit grant type那种,即token直接放客户端,因为native APP被认为比较安全。

web的话,token直接放客户端比较危险,但传统方法(包括oauth authorization code grant type)是要在session里放token的。

这个问题,其实也有办法解决。但你最好先问一下自己,真的要无session化吗?其实session一般而言是很难完全去掉的,就整个系统架构而言,你只不过是在你的编程视野内不用它而已。合理的使用,并无不可,不要搞原教旨主义。如果只有token放session里面,万一服务器崩溃,假设你应用处理得好,前端业务状态态能被持久化,那无非就是让用户重新登录然后回到刚才页面继续。比如,在线商城,用户只要把东西放购物车里,后台崩掉,也无非就是重登录,你的购物记录还在,可以继续操作。这只是粗略描述,具体细节要根据业务需求来定,但我的意思你应该能明白了吧。 你可以读读这个Post: Lift, State, and Scaling, 无关语言。可以想到的是,你们可能需要自己造很多轮子,因为很多事务在前端做的话没有成熟的工具,最后反倒拖慢了你们的创业。 简单来说,
1. 后端提供rest api,提供一个/verify供登录验证,然后后续操作都需要附带验证信息
2. 前端通过ember/angular做成webapp,使用ajax消费rest api,我在实际中就不用cookie,每次登录就是了,因为你已经是webapp了
3. 如果需要安全就上https,cookie这玩意我个人觉得能免则免 直接使用js api,授权问题很难解决,secret不能下载到浏览器,只能使用隐式授权,但大多数服务都不支持。。。 无后端方案?这个有过。记忆中有挺多的案例的。

无后端不是真的没有后端,API实现不也是后端之类的技术嘛。发展到现在应该已经基本没难点了。 题主的问题,可能是没有认识到服务端token和web session的区别。其实还好,和接口服务器通信肯定是token,web端的session肯定是先验证了服务端访问权限由web端生成的。
我们来过一下流程,
用户登录为例,
1. 用户登录,向api服务器发送验证信息
2. 服务器验证OK,返回一个token表示验证通过
3. web端创建一个登录session记录下当前登录态获取的token
4. 登录完成,跳转到应用页面
在上面之后,用户要看看ta的优惠券信息
1. 拿着登录时web端session里保存的token 和用户名等信息,调用优惠券接口
2. 返回优惠券信息
服务器在这个过程中做了2件事
1. 验证token合法性(存在性,过期与否,来源等)
2. 合法,调用服务返回优惠券信息,反之,报错。
在这里,你可以看到session是web端表现层用的,token是接口服务器的session,分清楚层次,就明朗了。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:23 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Sep 11, 2024 am 06:37 AM

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size Sep 07, 2024 am 06:35 AM

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Sep 07, 2024 am 06:39 AM

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:22 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Sep 12, 2024 pm 09:21 PM

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

Motorola Razr 50s shows itself as possible new budget foldable in early leak Motorola Razr 50s shows itself as possible new budget foldable in early leak Sep 07, 2024 am 09:35 AM

Motorola has released countless devices this year, although only two of them are foldables. For context, while most of the world has received the pair as the Razr 50 and Razr 50 Ultra, Motorola offers them in North America as the Razr 2024 and Razr 2

Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Sep 27, 2024 am 06:23 AM

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

See all articles