1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/test/e2e/mock-3box/server.js
Whymarrh Whitby 362e717eef
Fix node/no-deprecated-api issues (#9670)
Refs #9663

See [`node/no-deprecated-api`][1] for more information.

This change enables `node/no-deprecated-api` and fixes the issues raised by the rule.

  [1]:https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-deprecated-api.md

The change to the way that `punycode` is imported is to address the fact that
third-party module is hidden by the built-in. This is a silly hack but it works.
2020-10-22 11:33:45 -02:30

38 lines
974 B
JavaScript

const http = require('http')
const port = 8889
const database = {}
const requestHandler = (request, response) => {
response.setHeader('Content-Type', 'application/json')
if (request.method === 'POST') {
let body = ''
request.on('data', (chunk) => {
body += chunk.toString() // convert Buffer to string
})
request.on('end', () => {
const { key, data } = JSON.parse(body)
database[key] = data
response.setHeader('Access-Control-Allow-Headers', '*')
response.end('ok')
})
} else if (request.method === 'GET') {
const key = (new URL(request.url, 'https://example.org/')).searchParams.get('key')
response.setHeader('Access-Control-Allow-Headers', '*')
response.end(JSON.stringify(database[key] || ''))
} else {
response.end('unknown request')
}
}
const server = http.createServer(requestHandler)
server.listen(port, (err) => {
if (err) {
console.log('mock 3box server error: ', err)
}
})