[Open pit] UPX development diary

Sui Suinian

upxIs 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, nodewith seamless, Shuangwai, now has achieved a simple http-serverbut there are packaged upload npmthese 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 koaframework, I am from expressthe transition over, to get started quickly (although expressboth have almost forgotten ..)

Pit

In developing them, we met a lot of pits, but basically solved

  1. How to create a separate process (http-server)

I think this issue is too complex to be used directly child_processto 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
}
  1. How in Array.mapthe use of lower asyncand await?
// 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

Guess you like

Origin www.cnblogs.com/kozo4/p/11784963.html