Sui Suinian
upx
Is a gadget always wanted to do, the name is taken at random, I began to hope that it is a simple realization http-server
, so I used my relatively familiarnodejs
But later read, read, find handy, node
with seamless, Shuangwai, now has achieved a simple http-server
but there are packaged upload npm
these operations
On direct link: https://github.com/luxizhizhong/upx
Technology Architecture
With a common BS
But this time S
(Server) is used locallyapi
On the front end, with a react
+ react-weui
(but still ugly / escape)
The back-end using the koa
framework, I am from express
the transition over, to get started quickly (although express
both have almost forgotten ..)
Pit
In developing them, we met a lot of pits, but basically solved
- How to create a separate process (http-server)
I think this issue is too complex to be used directly child_process
to create a separate process
const { fork } = require('child_process')
require('colors')
const clear = require('clear')
module.exports = async (port, path)=> {
clear()
let fileName = `${ __dirname }/pullChildServer.js`
const jsServer = fork(
fileName,
[
`port=${port}`,
`path=${path}`
],
{
'stdio': 'ignore', // 父子进程间不建立通道
'detached': true // 让子进程能在父进程退出后继续运行
}
)
jsServer.unref()
return true
}
- How in
Array.map
the use of lowerasync
andawait
?
// https://flaviocopes.com/javascript-async-await-array-map
cosnt asyncFn = async item=> {
item.isShow = false
return item
}
cosnt getData = async ()=> {
return await Promise.all(lists.map(item=> asyncFn(item)))
}
Development log
I will continue to update
2019-11-02
- carry out
http-server