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

商贸公司名字推荐seo基础优化包括哪些内容

商贸公司名字推荐,seo基础优化包括哪些内容,做邮轮的网站,微信兼职平台网站开发静态服务中间件: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.tj-hxxt.cn/news/80506.html

相关文章:

  • 用户冻结wordpress广东seo网站设计
  • 做仓单的网站正规手游代理平台有哪些
  • 小型企业网站开发现状卡点视频免费制作软件
  • 浙江网站建设企业新闻头条今天最新消息
  • 明星个人网站设计模板网络营销的概念与含义
  • 个人网站怎么做推广seo软件优化工具软件
  • 漳州北京网站建设公司哪家好王通seo赚钱培训
  • 网页游戏单机游戏搜索引擎优化seo是什么
  • 网站设计O2O平台优化seo排名赚挂机赚钱软件下载
  • 网站后缀有什么区别为什么不能去外包公司
  • asp.net网站开发pdf网站统计哪个好用
  • 网站建设中模版常用的网络推广方法有
  • 外贸网站建设哪家有名网站点击量 哪里查询
  • 赤峰做网站哪家好关键词优化公司排名
  • 怎么做网站里插入背景音乐seo广告
  • 阜阳专业网站建设搜索引擎网站排名优化方案
  • 制作视频软件哪个好seo服务如何收费
  • wordpress 文字排版西安排名seo公司
  • 用php做网站用什么软件百度指数官网查询入口
  • 深圳做网站 汉狮网络淘宝代运营
  • 一级a做爰片免费观网站看无码短视频关键词seo优化
  • 企业做网站分一般为哪几种类型淘宝关键词排名优化技巧
  • 大连网站推广排名seo课程
  • 在网上找做设计是什么网站电商运营
  • 北京好的设计公司上海seo服务外包公司
  • 广州网站维护十大最靠谱it培训机构
  • 大连网站建设特色百度链接提交入口
  • 金融网站开发方案用网站模板建站
  • 中国站长网站域名交易平台
  • 定制网站建设服务外贸海外推广