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

商贸公司名字推荐亚马逊关键词优化怎么做

商贸公司名字推荐,亚马逊关键词优化怎么做,贵州建设监理网站,河北企业信息系统静态服务中间件:koa-static 中间件可以决定是否向下执行,如果自己可以处理,那么直接处理完毕结束,如果自己处理不了,next 方法会继续向下执行 新建 public 文件夹,里面添加 index.html、style.css 文件 …

静态服务中间件:koa-static

中间件可以决定是否向下执行,如果自己可以处理,那么直接处理完毕结束,如果自己处理不了,next 方法会继续向下执行

新建 public 文件夹,里面添加 index.html、style.css 文件

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>凯小默测试静态服务中间件koa-static</title><link rel="stylesheet" href="./style.css" /></head><body><h1>凯小默测试静态服务中间件koa-static</h1></body>
</html>
body {background-color: pink;
}

koa-static

npm i koa koa-static

用法:

const serve = require('koa-static');
const Koa = require('koa');
const app = new Koa();// $ GET /package.json
app.use(serve('.'));// $ GET /hello.txt
app.use(serve('test/fixtures'));// or use absolute paths
app.use(serve(__dirname + '/test/fixtures'));app.listen(3000);console.log('listening on port 3000');

业务代码 static.js 中使用 koa-static

const Koa = require("koa");
const path = require("path");
const bodyParser = require("koa-bodyparser");
// 使用自己实现的中间件
// const static = require("koa-static");
const static = require("./kaimo-koa-static");
const app = new Koa();
app.use(bodyParser());
app.use(static(__dirname));
app.use(static(path.resolve(__dirname, "public")));app.use((ctx, next) => {console.log(ctx.path, ctx.method);if (ctx.path == "/login" && ctx.method === "GET") {ctx.body = `<form action="/login" method="post">用户名:<input type="text" name="username"/><br/>密码:<input type="password" name="password"/><br/><button>提交</button></form>`;} else {return next();}
});app.use(async (ctx, next) => {console.log(ctx.path, ctx.method);if (ctx.path == "/login" && ctx.method === "POST") {ctx.body = ctx.request.body;} else {await next();}
});app.on("error", function (err) {console.log("error----->", err);
});app.listen(3000);

启动服务,访问 http://localhost:3000/index.html

在这里插入图片描述

nodemon static.js

下面实现自己的 koa-static,需要安装 mime

const path = require("path");
const fs = require("fs").promises;
const mime = require("mime");console.log("使用的是 kaimo-koa-static 中间件");
module.exports = function static(root) {return async (ctx, next) => {let filePath = path.join(root, ctx.path);try {let statObj = await fs.stat(filePath);// 判断是否是文件if (statObj.isFile()) {ctx.type = mime.getType(filePath) + ";charset=utf-8";ctx.body = await fs.readFile(filePath);} else {await next();}} catch (e) {await next();}};
};

在这里插入图片描述

在这里插入图片描述

http://www.wangmingla.cn/news/28537.html

相关文章:

  • 扫二维码直接进网站怎么做西安网站托管
  • 相亲网站绑定微信怎么做seo关键词优化费用
  • 如何提高网站访问量长沙百度快速优化排名
  • 什么网页可以做网站外包推广公司
  • 没有公司怎么做网站原创代写文章平台
  • 正版win10做win7系统下载网站优化seo是什么意思
  • 平泉建设局网站高端网站建设企业
  • 东莞做网站找微客巴巴商品促销活动策划方案
  • 县文化馆网站建设方案站长工具最近查询
  • wordpress 微博页面优化软件
  • 潍坊高端网站建设公司外包公司的优势和劣势
  • 企业网站管理系统 cms网络推广公司十大排名
  • 北京做网站的人友情链接免费发布平台
  • 宝丰网站制作效果好网站关键词排名服务
  • 门户网站开发维护合同范本saas建站平台
  • 怎么用wix做网站百度推广怎么注册账号
  • 代做备案网站google搜索引擎下载
  • 北斗手表官方网站网站推广公司哪家好
  • html音乐网站源码专业网页设计和网站制作公司
  • 嘉兴网站制作多少钱搜索引擎排名优化包括哪些方面
  • 做网站 用哪种西安seo优化排名
  • 做的网站怎么联网长沙谷歌seo
  • 广州led网站建设推广专员
  • 引蜘蛛网站seo搜索引擎工具
  • 招聘门户网站有哪些深圳网络营销
  • 网站后台能进前台空白如何优化网站
  • 爱是做的电影网站网络推广的方式
  • 专业做汽车网站优化排名自助建站平台源码
  • 盐山县做网站价格南京百度
  • 网站访客代码js唐山seo推广公司