knowyt/client/src/server/api/[proxy].js

17 lines
495 B
JavaScript

// based on rudimadima's code from
// https://github.com/nuxt/framework/discussions/1223#discussioncomment-3113017
import httpProxy from 'http-proxy';
export default defineEventHandler((event) => {
const proxy = httpProxy.createProxyServer({
target: 'http://localhost:32039/',
});
return new Promise((resolve, reject) => {
proxy.web(event.req, event.res, {});
proxy.on('response', () => resolve(null))
proxy.on('error', e => reject(e))
});
});