Skip to content

Instantly share code, notes, and snippets.

@milansimek
Last active May 22, 2023 14:14
Show Gist options
  • Save milansimek/00e7045908f7ebe179acd38fe6c5e3e3 to your computer and use it in GitHub Desktop.
Save milansimek/00e7045908f7ebe179acd38fe6c5e3e3 to your computer and use it in GitHub Desktop.
Server emit event from server only API endpoint
// src/routes/api/queue/add/+server.js
import { json } from "@sveltejs/kit";
import { ioServer } from "$lib/server/socketio/ioserver.js";
import PrintQueue from "$lib/repository/printQueue.js";
export async function GET(event) {
let fakeData = {
id: 'job_' + Math.random().toString(36).substr(2, 5),
}
let newItem = PrintQueue.newItem( fakeData, true);
ioServer.emit('printJobAdded', {
item: newItem.getData()
});
return json({'status':'success'});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment