<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>后端 &#8211; 「马马虎虎」</title>
	<atom:link href="https://www.gek6.cn/category/web-service/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.gek6.cn</link>
	<description>极客蜗牛-开发效率很慢的...</description>
	<lastBuildDate>Wed, 26 Jul 2023 08:28:43 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://www.gek6.cn/wp-content/uploads/2021/12/20211205200322145-32x32.png</url>
	<title>后端 &#8211; 「马马虎虎」</title>
	<link>https://www.gek6.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【cool-admin】接口参数校验Joi</title>
		<link>https://www.gek6.cn/%e3%80%90cool-admin%e3%80%91%e6%8e%a5%e5%8f%a3%e5%8f%82%e6%95%b0%e6%a0%a1%e9%aa%8c/</link>
					<comments>https://www.gek6.cn/%e3%80%90cool-admin%e3%80%91%e6%8e%a5%e5%8f%a3%e5%8f%82%e6%95%b0%e6%a0%a1%e9%aa%8c/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Wed, 26 Jul 2023 08:28:19 +0000</pubDate>
				<category><![CDATA[COOL-ADMIN]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=159</guid>

					<description><![CDATA[创建校验类 import { R&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h3>创建校验类</h3>
<pre><code>import { Rule, RuleType } from &#039;@midwayjs/validate&#039;;

export class SendVerifyCodeValidator {
  // 手机号
  @Rule(RuleType.string().label(&#039;手机号&#039;).length(11).required())
  phoneNum: string;
}

export class BindPhoneValidator {
  // 手机号
  @Rule(RuleType.string().label(&#039;手机号&#039;).length(11).required())
  phoneNum: string;
  // 验证码
  @Rule(RuleType.string().label(&#039;验证码&#039;).length(6).required())
  verifyCode: string;
}</code></pre>
<h3>在控制器上加上  <code>@Validate()</code> 即可</h3>
<pre><code>  /**
   * 绑定手机号
   */
  @Post(&#039;/bindPhoneNum&#039;)
  @Validate({
    errorStatus: httpCodeEnum.PARAMS_ERROR,
  })
  async bindPhoneNum(@Body() bindPhoneData: BindPhoneValidator) {
    // TODO 绑定...
    return this.ok(null);
  }</code></pre>
<h1>重点：自定义错误提示语</h1>
<pre><code>  // 验证码
  @Rule(
    RuleType.string().label(&#039;验证码&#039;).length(6).required().messages({
      &#039;string.length&#039;: &#039;{{#label}}位数错误&#039;,
      &#039;string.empty&#039;: &#039;验证码不能为空&#039;,
      &#039;any.required&#039;: &#039;验证码必填&#039;,
    })
  )
  verifyCode: string;</code></pre>
<h3>这么写 是不行的！！</h3>
<h3>需要在这里去定义</h3>
<pre><code>  @Post(&#039;/bindPhoneNum&#039;)
  @Validate({
    errorStatus: httpCodeEnum.PARAMS_ERROR,
    validationOptions: {
      messages: {
      &#039;string.length&#039;: &#039;{{#label}}位数错误&#039;,
      &#039;string.empty&#039;: &#039;{{#label}}不能为空&#039;,
      &#039;any.required&#039;: &#039;{{#label}}必填&#039;,
      },
    },
  })
  async bindPhoneNum(@Body() bindPhoneData: BindPhoneValidator)</code></pre>
<p>但是这样会更改所有字段的对应异常提示<br />
比如这个接口要校验手机号和验证码两个参数<br />
当手机号校验11位未通过，会提示 手机号位数错误<br />
当验证码校验6位未通过，会提示 验证码位数错误</p>
<h3>如果需要自定义验证器 并 提示自定义的异常信息</h3>
<pre><code>  // 验证码校验规则
  @Rule(
    RuleType.string()
      .label(&#039;验证码&#039;)
      .required()
      .custom((value, helpers) =&gt; {
        const reg = /^\d{6}$/;
        if (reg.test(value)) {
          return value;
        }
        throw new Error(&#039;格式错误&#039;);
      })
  )
  verifyCode: string;

  // 控制器中校验装饰器
  @Validate({
    errorStatus: httpCodeEnum.PARAMS_ERROR,
    validationOptions: {
      messages: {
        &#039;any.custom&#039;: &#039;{{#label}}{{#error.message}}&#039;,
      },
    },
  })

  // 最终响应
  {&quot;code&quot;:5001,&quot;message&quot;:&quot;\&quot;验证码\&quot;格式错误&quot;}
</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/%e3%80%90cool-admin%e3%80%91%e6%8e%a5%e5%8f%a3%e5%8f%82%e6%95%b0%e6%a0%a1%e9%aa%8c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Cool-Admin 开启跨域问题</title>
		<link>https://www.gek6.cn/cool-admin-%e5%bc%80%e5%90%af%e8%b7%a8%e5%9f%9f%e9%97%ae%e9%a2%98/</link>
					<comments>https://www.gek6.cn/cool-admin-%e5%bc%80%e5%90%af%e8%b7%a8%e5%9f%9f%e9%97%ae%e9%a2%98/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Tue, 04 Jul 2023 07:11:37 +0000</pubDate>
				<category><![CDATA[COOL-ADMIN]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=151</guid>

					<description><![CDATA[// /src/configur&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<pre><code>// /src/configuration.ts
import * as crossDomain from &#039;@midwayjs/cross-domain&#039;;
@Configuration({
  imports: [
    crossDomain,
  ],
  importConfigs: [join(__dirname, &#039;./config&#039;)],
})</code></pre>
<pre><code>// /src/config/config.default.ts

export default {
  cors: {
    // 允许跨域的方法，【默认值】为 GET,HEAD,PUT,POST,DELETE,PATCH
    allowMethods: &#039;*&#039;,
    // 设置 Access-Control-Allow-Origin 的值，【默认值】会获取请求头上的 origin
    // 也可以配置为一个回调方法，传入的参数为 request，需要返回 origin 值
    // 例如：http://test.midwayjs.org
    // 如果设置了 credentials，则 origin 不能设置为 *
    origin: &#039;*&#039;,
    // 设置 Access-Control-Allow-Headers 的值，【默认值】会获取请求头上的 Access-Control-Request-Headers
    allowHeaders: &#039;*&#039;,
    // 设置 Access-Control-Expose-Headers 的值
    exposeHeaders: &#039;*&#039;,
    // 设置 Access-Control-Allow-Credentials，【默认值】false
    // 也可以配置为一个回调方法，传入的参数为 request，返回值为 true 或 false
    credentials: false,
    // 是否在执行报错的时候，把跨域的 header 信息写入到 error 对的 headers 属性中，【默认值】false
    keepHeadersOnError: true,
    // 设置 Access-Control-Max-Age
    maxAge: 36000,
  },
}
</code></pre>
<h1>重点！后台管理的接口报错，经过排查是因为对 OPTIONS 请求未做特殊响应</h1>
<p><img decoding="async" src="https://foruda.gitee.com/images/1687833639383824912/a12f734e_1999285.png" alt="后台登录权鉴中间件修改" title="未命名1687833597.png" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/cool-admin-%e5%bc%80%e5%90%af%e8%b7%a8%e5%9f%9f%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>nvm安装Node16.x 使用npm安装任何依赖报错语法错误的问题</title>
		<link>https://www.gek6.cn/nvm%e5%ae%89%e8%a3%85node16-x-%e4%bd%bf%e7%94%a8npm%e5%ae%89%e8%a3%85%e4%bb%bb%e4%bd%95%e4%be%9d%e8%b5%96%e6%8a%a5%e9%94%99%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%e7%9a%84%e9%97%ae%e9%a2%98/</link>
					<comments>https://www.gek6.cn/nvm%e5%ae%89%e8%a3%85node16-x-%e4%bd%bf%e7%94%a8npm%e5%ae%89%e8%a3%85%e4%bb%bb%e4%bd%95%e4%be%9d%e8%b5%96%e6%8a%a5%e9%94%99%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%e7%9a%84%e9%97%ae%e9%a2%98/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Tue, 04 Jul 2023 07:11:08 +0000</pubDate>
				<category><![CDATA[NodeJS]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=149</guid>

					<description><![CDATA[报错信息： npm ERR!Un&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<p>报错信息：</p>
<pre><code>npm ERR!Unexpected token &#039;.&#039;</code></pre>
<h3>解决方案：</h3>
<ol>
<li>升级nvm版本 <a href="https://github.com/coreybutler/nvm-windows/releases">GitHub下载地址</a></li>
<li>卸载需要用的Node版本，再安装一遍即可
<ul>
<li><code>nvm uninstall 16.18.0</code></li>
<li><code>nvm install 16.18.0</code></li>
<li><code>nvm use 16.18.0</code></li>
</ul>
</li>
</ol>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/nvm%e5%ae%89%e8%a3%85node16-x-%e4%bd%bf%e7%94%a8npm%e5%ae%89%e8%a3%85%e4%bb%bb%e4%bd%95%e4%be%9d%e8%b5%96%e6%8a%a5%e9%94%99%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%e7%9a%84%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>「WordPress」自定义菜单</title>
		<link>https://www.gek6.cn/%e3%80%8cwordpress%e3%80%8d%e8%87%aa%e5%ae%9a%e4%b9%89%e8%8f%9c%e5%8d%95/</link>
					<comments>https://www.gek6.cn/%e3%80%8cwordpress%e3%80%8d%e8%87%aa%e5%ae%9a%e4%b9%89%e8%8f%9c%e5%8d%95/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Sun, 05 Dec 2021 11:57:36 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=63</guid>

					<description><![CDATA[注册菜单 后面不单独说明的话，根&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h3>注册菜单</h3>
<blockquote>
<p>后面不单独说明的话，根目录都是从主题目录出发</p>
</blockquote>
<p><code>/functions.php</code></p>
<pre><code class="language-php">&lt;?php
// 自定义 菜单注册函数
function register_my_menus() {
  register_nav_menus(
    array(
      // key 为后台管理-菜单管理中-关联操作时看到的
      // __(value) 这个为后台管理-自定义菜单-的菜单名称-或自己起个名字
      &#039;top_menu&#039; =&gt; __( &#039;top_menu&#039; ),
      // 可配置多个菜单 如 顶部的 底部的
      &#039;xxxx-menu&#039; =&gt; __( &#039;xxxxx&#039; )
     )
   );
 }
 add_action( &#039;init&#039;, &#039;register_my_menus&#039; );</code></pre>
<h3>关联菜单</h3>
<p><img decoding="async" src="https://thamiti-blog.oss-accelerate.aliyuncs.com/tuchuang/WordPress/image.png" alt="image" /></p>
<h3>调用菜单</h3>
<pre><code>&lt;div class=&quot;main-menu&quot;&gt;
    &lt;nav id=&quot;mobile-menu&quot;&gt;
            &lt;?php wp_nav_menu(array(
                &#039;container&#039; =&gt; &#039;&#039;,
                &#039;menu_class&#039; =&gt; &#039;&#039;,
                &#039;menu&#039; =&gt; &#039;primary&#039;,
                &#039;theme_location&#039; =&gt; &#039;top_menu&#039;,
                &#039;link_before&#039; =&gt; &#039;&lt;span&gt;&#039;,
                &#039;link_after&#039; =&gt; &#039;&lt;/span&gt;&#039;,
            )); ?&gt;
    &lt;/nav&gt;
&lt;/div&gt;</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/%e3%80%8cwordpress%e3%80%8d%e8%87%aa%e5%ae%9a%e4%b9%89%e8%8f%9c%e5%8d%95/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>宝塔面板使用MongoDB</title>
		<link>https://www.gek6.cn/%e5%ae%9d%e5%a1%94%e9%9d%a2%e6%9d%bf%e4%bd%bf%e7%94%a8mongodb/</link>
					<comments>https://www.gek6.cn/%e5%ae%9d%e5%a1%94%e9%9d%a2%e6%9d%bf%e4%bd%bf%e7%94%a8mongodb/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Sun, 05 Dec 2021 11:34:10 +0000</pubDate>
				<category><![CDATA[宝塔]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=51</guid>

					<description><![CDATA[1. 进入 MongoDB 安装&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h4>1. 进入 MongoDB 安装目录</h4>
<pre><code>cd /www/server/mongodb/bin</code></pre>
<h4>2. 进入 mongo 程序命令行</h4>
<pre><code>mongo</code></pre>
<h4>3. 打开user表</h4>
<pre><code>use admin</code></pre>
<h4>4. 查看用户列表</h4>
<pre><code>show users</code></pre>
<h4>5. 创建管理员账户</h4>
<blockquote>
<p>mongodb中的用户是基于身份role的，该管理员账户的 role是 userAdminAnyDatabase。admin用户用于管理账号，不能进行关闭数据库等操作。</p>
<pre><code>db.createUser({
user: &quot;admin&quot;,
pwd: &quot;password&quot;,
roles: [{
role: &quot;userAdminAnyDatabase&quot;,
db: &quot;admin&quot;
}]
})</code></pre>
<h4>6. 创建root账号</h4>
<p>超级管理员root。角色：root。root角色用于关闭数据库。</p>
<pre><code>
db.createUser({
user: &quot;root&quot;,
pwd: &quot;password&quot;,
roles: [{
role: &quot;root&quot;,
db: &quot;admin&quot;
}]
})</code></pre>
</blockquote>
<pre><code>#### 7. 创建用户自己的数据库的管理角色
> role: "dbOwner"代表数据库所有者角色，拥有最高该数据库最高权限。比如新建索引等，当账号管理员和超级管理员，可以为自己的数据库创建用户了。
- 这时候一定，一定要切换到所在数据库上去创建用户，不然创建的用户还是属于admin。
- 如果是读写角色的话，权限设置为role: "readWrite"。</code></pre>
<p>use {yourdatabase}</p>
<p>db.createUser({<br />
user: &quot;user&quot;,<br />
pwd: &quot;password&quot;,<br />
roles: [{<br />
role: &quot;dbOwner&quot;,<br />
db: &quot;yourdatabase&quot;<br />
}]<br />
})</p>
<pre><code>#### 8. 删除用户
> 删除用户必须由账号管理员来删，所以，切换到admin角色</code></pre>
<p>//切换到admin角色<br />
use admin<br />
db.auth(&quot;admin&quot;,&quot;password&quot;)<br />
删除单个用户<br />
db.system.users.remove({user:&quot;XXXXXX&quot;})<br />
删除所有用户<br />
db.system.users.remove({})</p>
<pre><code>

#### 9. 修改配置项 authorization: enabled 开启登录鉴权

#### 10. 授权远程登录</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/%e5%ae%9d%e5%a1%94%e9%9d%a2%e6%9d%bf%e4%bd%bf%e7%94%a8mongodb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>远程服务器终端 log保活</title>
		<link>https://www.gek6.cn/%e8%bf%9c%e7%a8%8b%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%bb%88%e7%ab%af-log%e4%bf%9d%e6%b4%bb/</link>
					<comments>https://www.gek6.cn/%e8%bf%9c%e7%a8%8b%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%bb%88%e7%ab%af-log%e4%bf%9d%e6%b4%bb/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Tue, 08 Dec 2020 11:47:49 +0000</pubDate>
				<category><![CDATA[NodeJS]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=59</guid>

					<description><![CDATA[痛点：直接在服务器上远程开发Eg&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<blockquote>
<p>痛点：直接在服务器上远程开发Egg.js 的服务。<br />
运行的dev终端 在下次打开时希望能继续看到 log</p>
</blockquote>
<h2>screen工具</h2>
<p>安装</p>
<pre><code class="language-bash">yum install screen -y</code></pre>
<p>1、新建一个screen窗口</p>
<pre><code class="language-bash">screen -S cmdname</code></pre>
<p>2、查看 窗口列表</p>
<pre><code class="language-bash">screen -ls</code></pre>
<p>3、退出当前的screen窗口</p>
<pre><code class="language-bash">exit</code></pre>
<p>4、进入（重连）到某个 窗口</p>
<p>10732 为第二步中查出来的ID</p>
<pre><code class="language-bash">screen -r 10732</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/%e8%bf%9c%e7%a8%8b%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%bb%88%e7%ab%af-log%e4%bf%9d%e6%b4%bb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>NVM 使用</title>
		<link>https://www.gek6.cn/nvm-%e4%bd%bf%e7%94%a8/</link>
					<comments>https://www.gek6.cn/nvm-%e4%bd%bf%e7%94%a8/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Tue, 08 Dec 2020 11:44:48 +0000</pubDate>
				<category><![CDATA[NodeJS]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=57</guid>

					<description><![CDATA[一、安装 windows 下载安&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h2>一、安装</h2>
<h3>windows</h3>
<h4>下载安装</h4>
<p>github直接下载最新安装包  一键安装<br />
<a href="https://github.com/coreybutler/nvm-windows/releases">https://github.com/coreybutler/nvm-windows/releases</a><br />
nvm-noinstall.zip：绿色免安装版，但使用时需进行 环境变量配置。<br />
nvm-setup.zip：安装版，推荐使用</p>
<h4>修改下载源</h4>
<p>nvm安装目录\settings.txt<br />
node_mirror: <a href="https://npm.taobao.org/mirrors/node/">https://npm.taobao.org/mirrors/node/</a><br />
npm_mirror: <a href="https://npm.taobao.org/mirrors/npm/">https://npm.taobao.org/mirrors/npm/</a></p>
<h3>linux</h3>
<p>下载安装</p>
<pre><code class="language-bash">curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash</code></pre>
<p>修改下载源</p>
<pre><code class="language-bash">export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/nvm-%e4%bd%bf%e7%94%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
