import http from 'http';
import { createSignalNode } from '@signal-js/node';
const signal = createSignalNode({
apiKey: process.env.SIGNAL_API_KEY!,
projectId: process.env.SIGNAL_PROJECT_ID!,
// endpoint is optional (defaults to https://api.trysignal.ai/)
});
function getSessionInfo(req: http.IncomingMessage) {
const headers = req.headers;
return {
sessionId: headers['x-signal-session-id'] as string | undefined,
windowId: headers['x-signal-window-id'] as string | undefined,
distinctId: headers['x-signal-distinct-id'] as string | undefined,
};
}
const server = http.createServer(async (req, res) => {
const { sessionId, windowId, distinctId } = getSessionInfo(req);
// Use signal.capture(), signal.identify(), etc. with sessionId, windowId, distinctId
});
server.listen(3000);