I might be close, but not quite there yet as the below throws Error: Invalid response from route /api: handler should return a Response object
, probably I do return just an object and not a Response?
routes/+server.ts
/** @type {import('./$types').RequestHandler} */
export async function GET({ url }) {
...
var server = http.createServer(function (req, res) {
pool.connect(async (err, client, done) => {
if (err) throw err;
const query = new QueryStream(querystring)
const stream = client.query(query);
stream.on('end', done)
return stream.pipe(JSONStream.stringify()).pipe(res)
})
})
return server;
}
src/lib/api.js
async function getDatabaseData (/** @type {string} */ url) {
// fetch internal server api.
const response = await fetch(url, {
method: 'GET',
});
let d = await response.json();
return d.message;
}
I assume returning ‘server’ is all wrong, but this is just my another attempt. Appreciate an heads up, thank you