一 、【webpack方面】regeneratorRuntime is not defined 参考链接
解决方法
npm i -D babel-core babel-polyfill babel-preset-es2015 babel-preset-stage-0 babel-loader
package.json
"devDependencies": {
"babel-core": "^6.0.20",
"babel-polyfill": "^6.0.16",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.0.15"
}
复制代码
.babelrc
{
"presets": [ "env", "stage-0" ]
}
复制代码
webpack.config.js
module.exports = {
entry: ['babel-polyfill', './test.js'],
output: {
filename: 'bundle.js'
},
module: {
loaders: [
{ test: /\.jsx?$/, loader: 'babel', }
]
}
};
复制代码
二、【webpack方面】 用webpack打包时, 出现警告: WARNING in ./~/express/lib/view.js Critical dependencies: 50:48-69 the request of a dependency is an expression @ ./~/express/lib/view.js 50:48-69
参考链接
解决方法:不捆绑node_modules。使用webpack的externals配置选项来解决这个问题
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
module.exports = {
entry: './src/main.js',
target: 'node',
output: {
path: path.join(__dirname, 'build'),
filename: 'backend.js'
},
externals: nodeModules
}
复制代码
三、 nginx搭建htts服务
四、 未开启阿里云上面的端口号
五、 npm install时会出现npm ERR! syscall rename错误,删除该项目里的package-lock.json即可
六、【 数据库方面】远程连接服务器数据库报错:Host ‘XXXXXX’ is blocked because of many connection errors
参考文章:blog.csdn.net/li_li_lin/a…
原因: 同一ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)终端的数据库连接而导致的阻塞;
解决方法:
可以更改max_connection_errors的值,即提高允许的max_connection_errors的数量
首先查看该属性设置为多大:命令:show global variables like '%max_connect_errors%';
然后修改该属性set global max_connect_errors = 1000
再次查看show global variables like '%max_connect_errors%';
复制代码
如果需要永久解决问题,得去修改mysql配置文件里相应属性。可能配置文件里没有这个属性,需要自己手动添加
注意:
当客户端连接服务端超时(超过connect_timeout),
服务端就会给这个客户端记录一次error,当出错的次数达到max_connect_errors
的时候,这个客户端就会被锁定。所以根据业务来尽量把这个值设置大一点,mysql
默认值为10,我们可以根据具体需要设置大一点,这里设置为1000.(并非越大越
好,越大被攻击时安全性越低)
复制代码
七、【 数据库方面】Failed to start mysql.service: Unit mysql.service not found.
我下载的是MariaDB,所以上述命令启动不起来,正确的方法如下
```
# systemctl start mariadb.service //启动服务
# systemctl enable mariadb.service //开机启动服务
# mysql -u root -p //登录mysql
```
复制代码
八、【 数据库方面】mysql数据库的timeout设置 每过一定时间,数据库就无法访问,后经了解,知道mysql有个timeout时间设置。在timeout时间内,如果没有访问数据库,则数据库就会关闭连接。
错误信息:、Cannot enqueue Query after fatal error
解决方法:用setInterval()每过一定时间访问数据库一次。
复制代码
九、【nginx 方面】搭建 https服务时, 因为poxy-pass属性,踩了一天的坑。
nginx中的listen 监听的端口号不能和服务端项目运行的端口号相同
一定要注意poxy-pass的值是域名加端口号, 域名是127.0.0.1(代表本机, 即服务器上的linux系统),端口号是服务端项目运行的端口号。
复制代码
十、 known_hosts 引发的问题
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
a7:a8:f2:97:94:33:58:b7:9d:bc:e0:a6:6b:f7:0a:29.
Please contact your system administrator.
Add correct host key in /home/ramesh/.ssh/known_hosts to get rid of this message.
Offending key in /home/ramesh/.ssh/known_hosts: 6
Permission denied (publickey,password).
复制代码
原因:ssh会把你每个你访问过计算机的公钥(public key)都记录在~/.ssh/known_hosts。当下次访问相同计算机时,OpenSSH会核对公钥。如果公钥不同,OpenSSH会发出警告, 避免你受到DNS Hijack之类的攻击。
解决方法:删除known_hosts文件里面对应的那条记录
复制代码
十一:sql语句错误
我这样写 sql = INSERT INTO categorytable (category_name) values (${data.categoryName})
报错: Unknown column '肉' in 'field list'
应该这样写,目的是为了转换为字符串sql = INSERT INTO categorytable (category_name) values ('${data.categoryName}')
十二、当使用远程数据库之后,node app.js报如下的错误
ER_HOST_NOT_PRIVILEGED: Host '117.32.216.107' is not allowed to connect to this MySQL server
十三、nodejs使用async/await同步操作mysql
function getCategoryById(id) {
var sql = `SELECT * from categorytable WHERE category_id=${id}`;
var data = {};
return new Promise((resolve, reject) => {
connection.query(sql, ( err, result) => {
if ( err ) {
reject( err )
} else {
resolve( result )
}
})
})
}
const searchCategoryById = async (ctx, next) => {
if(isNaN(ctx.params.id)){
return; //不是数字
}
const id = ctx.params.id;
var data = await getCategoryById(id);
ctx.status = 200;
ctx.body = {
code: 0,
msg: "请求成功",
data:{
data
}
};
};
复制代码
十四:koa不返回状态码时,前端接口请求时,会显示404。通过看koa源码发现, koa的status默认值为404,所以我们必须显示的指定status = 200.