当前位置: 首页 > news >正文

百度蜘蛛池自动收录seo北京网站搜索引擎优化

百度蜘蛛池自动收录seo,北京网站搜索引擎优化,军事新闻播报最新,美德的网站建设原生node封装一个简易的服务器, 把前面几天的知识揉和起来做一个服务器基础实现, 首页访问, 静态资源服务器, 特定接口封装, 404app.js 服务器入口文件 app.js node app.js即可启动服务器 const { start } require(./modules/server); start();require_modules.js 整合模块导…原生node封装一个简易的服务器, 把前面几天的知识揉和起来做一个服务器基础实现, 首页访问, 静态资源服务器, 特定接口封装, 404app.js 服务器入口文件 app.js node app.js即可启动服务器 const { start } require(./modules/server); start();require_modules.js 整合模块导出 const url require(url); const path require(path); const http require(http); const querystring require(querystring); const fs require(fs); const multiparty require(multiparty);module.exports {url,path,http,querystring,fs,multiparty }; server.js server 启动模块 const { http } require(./require_modules); const { port, host } require(./config); const { route } require(./router);function start() {const server http.createServer((req, res) {route(req, res);});server.listen(port, host, () {console.log(server listening in http://${host}:${port});}); } module.exports { start }; router.js 路由模块, 以及接口处理函数对照表 const { url } require(./require_modules); const { host, port } require(./config); const { staticHanlder, indexHanlder, tableHanlder, notFind } require(./hanlder); const hanlder {/index: indexHanlder,/static: staticHanlder,/index: indexHanlder,/getTableData: tableHanlder,404: notFind }; const route (req, res) {const thisURL new URL(http://${host}:${port}${req.url});let pathname thisURL.pathname;if (pathname /) {pathname /index/;}const thisHanlder Object.entries(hanlder).find(([key, val]) {let reg new RegExp(^${key}/.*);return reg.test(pathname);})?.[1] ?? hanlder[404];thisHanlder(req, res, pathname); }; module.exports { route };hanlder.js 接口处理函数模块 const { fs, path, querystring } require(../modules/require_modules); const { getMimeType } require(../modules/mime_type); const { root } require(./config); const { host, port } require(./config);function staticHanlder(req, res, pathname) {res.writeHeader(200, { content-type: getMimeType(pathname) });const filePath path.join(root, pathname);fs.stat(filePath, (err, stats) {if (err) {notFind(req, res, pathname);return;}if (!stats) {notFind(req, res, pathname);return;}if (stats.isDirectory()) {notFind(req, res, pathname);return;}if (stats.isFile()) {fs.readFile(filePath, (err, data) {if (err) {notFind(req, res, pathname);}res.writeHeader(200, { content-type: getMimeType(pathname) });res.end(data);});return;}}); } function indexHanlder(req, res, pathname) {res.writeHeader(200, { content-type: text/html;charsetutf-8 });res.end(!DOCTYPE htmlhtml langenheadmeta charsetUTF-8 /meta nameviewport contentwidthdevice-width, initial-scale1.0 /titleindex/title/headbodyh1欢迎~/h1/body/html); } function tableHanlder(req, res, pathname) {const thisURL new URL(http://${host}:${port}${req.url});let search thisURL.search.replace(?, );const searchInfo querystring.parse(search);let start Number(searchInfo.start) || 0;let end Number(searchInfo.end) || start 10;const jsonPath path.join(root, /data/table.json);fs.readFile(jsonPath, (err, data) {if (err) {notFind(req, res, pathname);return;}const jsonData JSON.parse(data.toString(utf-8));const resData jsonData.slice(start, end);res.writeHeader(200, { content-type: application/json;charsetutf-8 });res.end(JSON.stringify(resData));}); }function notFind(req, res, pathname) {res.writeHeader(404, { content-type: text/html;charsetutf-8 });res.end(!DOCTYPE htmlhtml langenheadmeta charsetUTF-8 /meta nameviewport contentwidthdevice-width, initial-scale1.0 /title404/title/headbodyh1not find/h1/body/html); } function serverError(req, res, pathname) {res.writeHeader(500, { content-type: text/html;charsetutf-8 });res.end(!DOCTYPE htmlhtml langenheadmeta charsetUTF-8 /meta nameviewport contentwidthdevice-width, initial-scale1.0 /title500/title/headbodyh1server error/h1/body/html); } module.exports {staticHanlder,indexHanlder,tableHanlder,notFind,serverError };mime_type.js 其它模块, 用于获取媒体文件类型 const { path } require(../modules/require_modules); const MIME_TYPE {css: text/css,gif: image/gif,html: text/html,ico: image/x-icon,jpeg: image/jpeg,jpg: image/jpeg,js: text/javascript,json: application/json,pdf: application/pdf,png: image/png,svg: image/svgxml,swf: application/x-shockwave-flash,tiff: image/tiff,txt: text/plain,wav: audio/x-wav,wma: audio/x-ms-wma,wmv: video/x-ms-wmv,xml: text/xml };function getMimeType(pathname) {let ext path.extname(pathname).replace(., ).toLowerCase();if (!ext) {ext pathname;}return MIME_TYPE[ext] || MIME_TYPE[txt]; } module.exports {getMimeType };config.js 其它模块 服务器基本信息配置 module.exports {root: process.cwd(),host: 127.0.0.1,port: 3008 };其实这就是node框架express做的事情 封装服务器有着比较繁琐的过程, 这只是一个简单的模型演示, 比如需要封装上传文件的接口, 你可以用到第三方库multiparty, 需要处理ajax跨域, 你可以封装一个前面学的跨域处理函数 :-)
http://www.hkea.cn/news/14481909/

相关文章:

  • 建网站和做微信哪个好设计师网课
  • 自己如何做简单网站南网站建设
  • 网站建设费用归类网站建设的单可以刷吗
  • 网站做的好有什么用网站建设好还需要续费吗
  • 高中制作网站怎么做网站维护 内容
  • 佛山专注网站制作细节做外贸网站效果好吗
  • 网站添加对联广告代码node.js网站开发合适吗
  • 辽宁建设信息网站链接关系 网站层次结构
  • 网站地址是什么做网站的需求调研
  • 网站推广销售做电影网站不放国内主机
  • 标准品购买网站娱乐网站开发多少钱
  • jsp做网站都可以做什么百度搜索高级搜索
  • iis网站asp.net部署手机对比参数配置
  • 常用的网站类型有哪些把自己做的网站进行app封包
  • 做ui设计用什么网站静安做网站
  • 模拟百度搜索词进入网站网站安全建设方案步骤
  • 请人建网站需要多少钱公司网站设计与实现
  • 站酷网app淘宝怎么设置关键词搜索
  • 网站文章伪原创怎么做wordpress 多域名 插件
  • ui设计参考网站有哪些企业培训平台
  • 菲律宾网站网站建设网站根目录怎么找
  • 网站访问量来源电子商务网站开发实
  • 怎样给一个公司做网站菏砖网站建设
  • 自己做购物网站网络广告策划书模板
  • 商城网站多少钱西安市城市建设管理局网站
  • 宣传不网站wordpress 幻灯片标签
  • 商务网站建设的主流程揭阳市建设发展总公司网站
  • 网站备案提交资料天津专业做网站的公司
  • 陕西省建设厅三类人员报名网站设计网站公司都选亿企邦
  • 城市建设管理网站做韦恩图的网站