当前位置:网站首页>1-10 respond to client content according to different URLs
1-10 respond to client content according to different URLs
2022-06-30 21:29:00 【Endless pie】
According to url Content of response client
const http = require('http')
// **1. Import http modular **
// **2. establish web Server instance **
const server = http.createServer()
// **3. Bind to the server instance request event , Listen for client requests **
server.on('request', (req, res) => {
// Obtain requested url Address
const url = req.url
// Set the default response content to 404 not found
let content = '<h1>404 not found</h1>'
// Judge whether the user's request is / perhaps index.html home page
// Judge whether the user's request is /about.html
if (url == '/' || url == '/index.html') {
content = '<h1> home page </h1>'
} else if (url == '/about.html') {
content = '<h1> About </h1>'
}
// Set up Content-type Response head , Prevent Chinese miscoding
res.setHeader('Content-Type', 'text/html;charset=utf-8')
// Use res.end() Respond the content to the client
res.end(content)
})
server.listen(80, () => {
console.log('server running at http://127.0.0.1')
})
边栏推荐
- WebRTC系列-网络传输之本地scoket端口
- Four Misunderstandings of Internet Marketing
- Encryption and decryption and the application of OpenSSL
- Reading notes of Clickhouse principle analysis and Application Practice (1)
- It is urgent for enterprises to protect API security
- Oracle 数据库表结构 Excel 导出
- Ssh server configuration file parameter permitrootlogin introduction
- sdfsdf
- 3Ds Max 精模obj模型导入ArcGIS Pro (二)要点补充
- ceshi deces
猜你喜欢
随机推荐
Digital currency: far-reaching innovation
针对美国国家安全局“酸狐狸”漏洞攻击武器平台的分析与应对方案建议
MySQL高级篇3
Encryption and decryption and the application of OpenSSL
How to run jenkins build, in multiple servers with ssh-key
Internet of things botnet gafgyt family and backdoor vulnerability exploitation of Internet of things devices
你我他是谁
Sqlserver string type converted to decimal or integer type
Reading notes of Clickhouse principle analysis and Application Practice (2)
1-3 使用SQL管理数据库
等级测评是什么意思?工作流程包含哪些?
Icml2022 | utility theory of sequential decision making
A group of K inverted linked lists
申请Vector 总线协议彩图壁纸挂画,非常棒哦!
Spatiotemporal data mining: an overview
Understanding polymorphism
k个一组反转链表
电子方案开发——智能跳绳方案
Four Misunderstandings of Internet Marketing
What happens when word encounters an error while trying to open a file?









