QA
GitbookKb2021-01-17
Q1 SQL error
sqlMessage: “Host ‘static-ip-242-196-65-202.rev.dyxnet.com’ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’”
解析三种类型的 form 数据:
- Text
- Date
- Number
- 前端传 boolean 类型时,要传 true/false,不要‘true’, ’false‘。
- 日期统一传‘yyyy-mm-dd’,不要其它格式。
const datetime = "abcde"; // 当原时间为非法参数时
moment(datetime).format("YYYYMMDD");Q2 Express redirect
router.get("/a", function (req, res) {
res.redirect("/b");
});
res.redirect("/foo/bar");
res.redirect("http://example.com");
res.redirect(301, "http://example.com");
res.redirect("../login");Q3 Promise.all
await Promis.all(promises);
const f1 = fetch('/mxbl/contract');
const f2 = fetch('/mxbl/file_informaiton')
Promise.all([f1, f2]).then(([res1, res2]) => {
console.log('Results', res1, res2)
});
app.post('/mxbl/', async (req, res) => {
var data = await promise.all(...)
res.json(data);
});
let allPromise = Promise.all([readFile('file1.txt'), readFile('file2.txt')])
allPromise.then(console.log, console.error)Q4 GET /api/passphrase 404
Q5: 操作失败
Unexpected token o in JSON at position 0
A: 期望返回 JSON,但返回非 JSON。
用res.json替代req.send
Q6: URIError: Failed to decode
URIError: Failed to decode param ‘/risk-management/%C3%CB%D0%C5/%D2%D1%BF%AA%C3%CB%D0%C5’
<html lang="zh-CN"></html>Q7: numberGenerator 重复问题
const numberGenerator = (item = 1, prefix = 'RD') => {
const ymd = getyyyyMMdd();
const mrd = Math.ceil(Math.random() * 100000);
return `${prefix}${item}${ymd}${mrd}`;
};npm shortid
Q8: APP crash
Unhandled rejection SequelizeDatabaseError: Incorrect integer value: ‘null’ for column ‘adddaysnumber’ at row 1
add_days_number: { //增加天数
type: DataTypes.INTEGER,
defaultValue: 0,
},- body.adddaysnumber = body.adddaysnumber || 0;
Q9: Sequlelize MySQL Invalid Date
- 如果输入日期为空,则 date = null; MySQL 接收 NULL 作为空日期。
- Decimal(10,2)存两位小数。
Q10: enterprisenameUNIQUE must be unique
🪕 More
📑 Express URIError: Failed to decode param
public/index.html: zh-Hans-CN, zh-CN:
<html lang="zh-CN"></html>- application/json
The MIME media type for JSON text is application/json. The default encoding is UTF-8.
language-extlang-script-region-variant-extension-privateuse
语言文字种类-扩展语言文字种类-书写格式-国家和地区-变体-扩展-私有
zh-CN 中文 (简体, 中国大陆) 对应 cmn-Hans-CN 普通话 (简体, 中国大陆)📑 .env, ~/.bash_profile, cross-env
环境变量放在哪里比较好?
- dotenv (.env)
- localenv (.env.local)
- process.env
📑 代理 IP 还是 localhost?
fetch, request需要前面加上协议名称 http。
📑 Key Takeaways (copy from graphql/apollo.md)
- If you want to execute
awaitcalls in series, use afor-loop(or any loop without a callback). - Don’t ever use
awaitwithforEach. Use afor-loop(or any loop without a callback) instead. - Don’t
awaitinsidefilterandreduce. Alwaysawaitan array of promises withmap, thenfilterorreduceaccordingly.
📑 try - await - catch
const [mutate] = useMutation(YOUR_MUTATION);
const [data, setData] = useState();
const [error, setError] = useState();
const handleClick = async () => {
try {
const { date } = await mutate();
setData(data);
} catch (e) {
setError(e);
}
};