-
-
Save milansimek/00e7045908f7ebe179acd38fe6c5e3e3 to your computer and use it in GitHub Desktop.
Server emit event from server only API endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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