当前位置:网站首页>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')
})
边栏推荐
- Testing media cache
- 升级kube出现unknown flag: --network-plugin
- 布隆过滤器
- It is urgent for enterprises to protect API security
- 1-17 express中间件
- Sqlserver string type converted to decimal or integer type
- Arcmap|assign values to different categories of IDS with the field calculator
- 雷达数据处理技术
- 利用日志服务器输出各种apache的日志的TOPN
- Markdown notes concise tutorial
猜你喜欢

防范未授权访问攻击的十项安全措施

Multi table operation - foreign key constraint

ArcGIS construction and release of simple road network data service and rest call test

Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
一文读懂什么是MySQL索引下推(ICP)

文本识别-SVTR论文解读

SQL server extracts pure numbers from strings

文本生成模型退化怎么办?SimCTG 告诉你答案

jupyter notebook/lab 切换conda环境

网络营销之四大误解
随机推荐
Text recognition svtr paper interpretation
时空数据挖掘:综述
ClickHouse distributed表引擎
Markdown笔记简明教程
漫谈Clickhouse Join
Markdown notes concise tutorial
等级测评是什么意思?工作流程包含哪些?
興奮神經遞質——穀氨酸與大腦健康
Fletter nested hell? No, constraintlayout to save!
Arcmap|assign values to different categories of IDS with the field calculator
激发新动能 多地发力数字经济
1-18 创建最基本的express服务器&创建路由的API模块
Is it safe to open an account for stock trading on mobile phones?
开发属于自己的包
Coefficient of variation method matlab code [easy to understand]
It is urgent for enterprises to protect API security
Analysis and proposal on the "sour Fox" vulnerability attack weapon platform of the US National Security Agency
oprator-1初识oprator
Reading notes of Clickhouse principle analysis and Application Practice (2)
Adobe-Photoshop(PS)-脚本开发-去除文件臃肿脚本