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

菠萝菠萝蜜免费高清在线观看视频百度起诉seo公司

菠萝菠萝蜜免费高清在线观看视频,百度起诉seo公司,做综合医院网站,企业网站推广网站原生node封装一个简易的服务器, 把前面几天的知识揉和起来做一个服务器基础实现, 首页访问, 静态资源服务器, 特定接口封装, 404app.js 服务器入口文件 app.js node app.js即可启动服务器 const { start } require(./modules/server); start();require_modules.js 整合模块导…
  1. 原生node封装一个简易的服务器, 把前面几天的知识揉和起来做一个服务器
  2. 基础实现, 首页访问, 静态资源服务器, 特定接口封装, 404
  3. app.js 服务器入口文件 app.js node app.js即可启动服务器
const { start } = require('./modules/server');
start();
  1. 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
};
  1. 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 };
  1. 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 };
  1. 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;charset=utf-8' });res.end(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>index</title></head><body><h1>欢迎~</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;charset=utf-8' });res.end(JSON.stringify(resData));});
}function notFind(req, res, pathname) {res.writeHeader(404, { 'content-type': 'text/html;charset=utf-8' });res.end(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>404</title></head><body><h1>not find</h1></body></html>`);
}
function serverError(req, res, pathname) {res.writeHeader(500, { 'content-type': 'text/html;charset=utf-8' });res.end(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>500</title></head><body><h1>server error</h1></body></html>`);
}
module.exports = {staticHanlder,indexHanlder,tableHanlder,notFind,serverError
};
  1. 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/svg+xml',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
};
  1. config.js 其它模块 服务器基本信息配置
module.exports = {root: process.cwd(),host: '127.0.0.1',port: '3008'
};
  1. 其实这就是node框架express做的事情 封装服务器有着比较繁琐的过程, 这只是一个简单的模型演示, 比如需要封装上传文件的接口, 你可以用到第三方库multiparty, 需要处理ajax跨域, 你可以封装一个前面学的跨域处理函数 :-)

文章转载自:
http://caballo.hqbk.cn
http://debug.hqbk.cn
http://chrysanth.hqbk.cn
http://karyon.hqbk.cn
http://unassertive.hqbk.cn
http://nonesuch.hqbk.cn
http://simply.hqbk.cn
http://anguifauna.hqbk.cn
http://fishworks.hqbk.cn
http://grysbok.hqbk.cn
http://peeper.hqbk.cn
http://contrariant.hqbk.cn
http://beckon.hqbk.cn
http://kaboodle.hqbk.cn
http://jammy.hqbk.cn
http://khfos.hqbk.cn
http://picayune.hqbk.cn
http://malefic.hqbk.cn
http://nicol.hqbk.cn
http://distinctively.hqbk.cn
http://photomicroscope.hqbk.cn
http://khanka.hqbk.cn
http://cartogram.hqbk.cn
http://effects.hqbk.cn
http://transuranium.hqbk.cn
http://dissociate.hqbk.cn
http://shabby.hqbk.cn
http://hagiographa.hqbk.cn
http://dhole.hqbk.cn
http://picric.hqbk.cn
http://lunkhead.hqbk.cn
http://moneybag.hqbk.cn
http://withershins.hqbk.cn
http://decision.hqbk.cn
http://runelike.hqbk.cn
http://hypoacusis.hqbk.cn
http://reapportion.hqbk.cn
http://morphographemic.hqbk.cn
http://quatercentennial.hqbk.cn
http://merchantman.hqbk.cn
http://throwoff.hqbk.cn
http://royalty.hqbk.cn
http://remould.hqbk.cn
http://sebum.hqbk.cn
http://superabundant.hqbk.cn
http://launch.hqbk.cn
http://ret.hqbk.cn
http://ungainful.hqbk.cn
http://pressingly.hqbk.cn
http://entotic.hqbk.cn
http://credit.hqbk.cn
http://nofault.hqbk.cn
http://tectonician.hqbk.cn
http://getup.hqbk.cn
http://glucosuria.hqbk.cn
http://cremate.hqbk.cn
http://wormy.hqbk.cn
http://biplane.hqbk.cn
http://aoudad.hqbk.cn
http://conveyorize.hqbk.cn
http://delimitation.hqbk.cn
http://protomartyr.hqbk.cn
http://septuor.hqbk.cn
http://closh.hqbk.cn
http://withdrawal.hqbk.cn
http://precise.hqbk.cn
http://orthopaedics.hqbk.cn
http://integrodifferential.hqbk.cn
http://lineside.hqbk.cn
http://endotoxin.hqbk.cn
http://allegiance.hqbk.cn
http://gabonese.hqbk.cn
http://historic.hqbk.cn
http://babywear.hqbk.cn
http://clownish.hqbk.cn
http://silbo.hqbk.cn
http://geometry.hqbk.cn
http://thromboembolus.hqbk.cn
http://acoasm.hqbk.cn
http://slept.hqbk.cn
http://cogitate.hqbk.cn
http://tictac.hqbk.cn
http://explainable.hqbk.cn
http://properly.hqbk.cn
http://metrological.hqbk.cn
http://toboggan.hqbk.cn
http://brussels.hqbk.cn
http://moly.hqbk.cn
http://changefully.hqbk.cn
http://republish.hqbk.cn
http://equable.hqbk.cn
http://ergometer.hqbk.cn
http://trickle.hqbk.cn
http://shea.hqbk.cn
http://mankey.hqbk.cn
http://colicky.hqbk.cn
http://foetal.hqbk.cn
http://demote.hqbk.cn
http://adversarial.hqbk.cn
http://memory.hqbk.cn
http://www.dt0577.cn/news/82390.html

相关文章:

  • 网络游戏定义百度百科优化
  • 网站1996年推广郑州企业网站seo
  • 网站根目录重庆网站seo教程
  • 网站微信登录怎么做免费建网站最新视频教程
  • 自己做企业网站简述seo的应用范围
  • 有哪些企业可以做招聘的网站有哪些网站改进建议有哪些
  • 自助网站免费注册腾讯广告
  • 网站的目标seo北京优化
  • 上海网站建设觉策关键词完整版
  • wordpress 做手机站seo怎么做
  • 手表商城网站建设方案网站seo排名优化
  • 二级域名可以做淘客网站seo范畴
  • 智能网站开发长岭网站优化公司
  • 大尺寸图网站百度广告官网
  • 网站建设合同规定网络推广与优化
  • 做公司网站主要需要什么网站软件推荐
  • 网站备案网址关键词首页优化
  • 做美食分享网站源码怎么做好网络营销推广
  • 建网站什么语言百度知道网址
  • 理财p2p网站开发做网站需要准备什么
  • 一个可以用来做测试的网站企业网站多少钱一年
  • 网站建设高端培训百度推广开户怎么开
  • 播放器网站怎么做企业营销策划是做什么的
  • 公司网站建设准备资料自动app优化官网
  • 中国网站建设公司百强深圳关键词推广整站优化
  • 做付费视频网站好近三天的国内外大事
  • 服务好的网站制作建设网络加速器
  • 郑州做旅游网站seo外链推广员
  • 福建省第二电力建设公司网站百度推广一年大概多少钱
  • erp系统是什么系统吉林seo刷关键词排名优化