Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
149
第 14章
路由
路由是你的网站或
Web
服务最重要的方面之一。幸运的是,
Express
中的路由十分简单、
灵活且稳定。通过
路由
这种机制,就可以让请求(由
URL
和
HTTP
方法来指定)与处理
它们的代码相匹配。正如前面已经提到的,路由过去是基于文件的,而且很简单。例如,
如果你把文件
foo/about.html
放到你的网站上
,就可以在浏览器上通过路径
/foo/about.html
访问它。不过,这种方式虽然简单但不够灵活。而且,不管你是否已注意到,在
URL
中
带上
html
这种方式如今已经非常过时了。
在深入到
Express
路
由的技术层面之前,应该先讨论一下
信息架构
(
IA
)这个概念。
IA
指
的是内容的概念组织方式。在开始考虑路由之前,先规划好一套可扩展(但又不过度复
杂)的
IA
,将来可以带来巨大的好处。
在众多关于
IA
的优秀文章中有一篇文章充满智慧而又永不过时,它就是“
Cool URIs don
’
t
change
”
,作者是
Tim Berners-Lee
,实际上他是
发明互联网
的人。现在你就可以(也应该)
读一读。这篇关于互联网技术的文章写于
1998
年
,那时的结论到今天还能适用的已经不
多了,让我们好好体会一下。
这篇文章向我们提出了应该承担起来的崇高责任:
分配一套
URI
,让它们能够坚持到
2
年
后、
20
年后、
200
年后,这是作为网站管
理员的职责。这需要思索、需要组织、需要决心。
——
T
im Berners-Lee
我总是想象,如果
We
b
设计也像其他的工程领域一样要求职业许可,那么我们就会做类
150
|
第
14
章
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099