文件
jw-beauty/server/scripts/local-server.js
T

28 行
885 B
JavaScript

require('dotenv').config({ path: require('path').join(__dirname, '..', '.env') })
const http = require('http')
const config = require('../src/config')
const { handle } = require('../src/app')
const server = http.createServer(async (req, res) => {
const chunks = []
req.on('data', chunk => chunks.push(chunk))
req.on('end', async () => {
const url = new URL(req.url, 'http://localhost')
const event = {
httpMethod: req.method,
path: url.pathname,
headers: req.headers,
queryStringParameters: Object.fromEntries(url.searchParams.entries()),
body: Buffer.concat(chunks).toString('utf8')
}
const result = await handle(event)
res.writeHead(result.statusCode, result.headers)
res.end(result.body || '')
})
})
server.listen(config.port, () => {
console.log('SCF local server listening on http://localhost:' + config.port)
})