Mini-Node-Server


const server = http.createServer((request, response) => {
  if (request.method === 'OPTIONS') {
    response.writeHead(200, defaultCorsHeader)
    response.end()
  }
  
  if (request.method === 'POST' && request.url ==='/upper') {
    let body = []
    request.on('data', (chunk) => {
    body.push(chunk)
    }).on('end', () => {
    body = Buffer.concat(body).toString().toUpperCase()
    response.writeHead(200, defaultCorsHeader)
    response.end(body)
    })
  }
  else if (request.method === 'POST' && request.url ==='/lower') {
    let body = []
    request.on('data', (chunk) => {
    body.push(chunk)
    }).on('end', () => {
    body = Buffer.concat(body).toString().toLowerCase()
    response.writeHead(200, defaultCorsHeader)
    response.end(body)
    })
  }
  else {
    response.on('error', (err) => {
      response.writeHead(400, defaultCorsHeader)
      console.error(err)
    })
  }
});