OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-wallet-lib / create-wallet-server.cjs

38 lines · javascript ref:
// Wrapper to create wallet HTTP server (reusing terminal version logic)
// This allows desktop and terminal versions to share the same API implementation

const http = require('bare-http1')
const path = require('bare-path')

// Import the terminal version's wallet server
// Since lib/ is symlinked to ../hyper-wallet/lib/, we can require the parent's server
const parentWalletServer = path.join(__dirname, '../../hyper-wallet/wallet-server.cjs')

module.exports = async function createServer(port = 4004) {
  // For now, just start the HTTP server directly
  // TODO: Extract server creation logic from wallet-server.cjs into a reusable function

  const server = http.createServer((req, res) => {
    res.setHeader('Access-Control-Allow-Origin', '*')
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization')

    if (req.method === 'OPTIONS') {
      res.statusCode = 200
      res.end()
      return
    }

    res.statusCode = 200
    res.setHeader('Content-Type', 'application/json')
    res.end(JSON.stringify({ status: 'ok', message: 'API placeholder - use terminal version server logic' }))
  })

  return new Promise((resolve, reject) => {
    server.listen(port, 'localhost', (err) => {
      if (err) reject(err)
      else resolve(server)
    })
  })
}