-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
67 lines (56 loc) · 1.39 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as dotenv from 'dotenv';
import express from 'express';
import { serve } from 'inngest/express';
dotenv.config();
import { getFunctions, inngest } from './inngest';
const PORT = 3030;
const app = express();
app.use(express.json());
app.get('/', (req, res) => {
res.json({ success: true });
});
const functions = getFunctions();
app.use(
'/api/inngest',
serve({
client: inngest,
functions,
})
);
app.listen(PORT, async () => {
console.log(`✅ Server started on localhost:${PORT}
➡️ Inngest running at http://localhost:${PORT}/api/inngest`);
// Attempt to self-register the app after deploy
if (process.env.RENDER_EXTERNAL_URL) {
console.log(
`Attempting self-register. Functions: `,
functions.map((f) => f.name).join(', ')
);
const inngestURL = new URL('/api/inngest', process.env.RENDER_EXTERNAL_URL);
const result = await fetch(inngestURL, {
method: 'PUT',
});
await sleep(2000);
try {
const json = await result.json();
console.log(
`Register attempted:`,
inngestURL.toString(),
result.status,
json
);
} catch (err) {
console.log(
`Register failed:`,
inngestURL.toString(),
result.status,
result.body
);
}
}
});
function sleep(t: number): Promise<void> {
return new Promise((res) => {
return setTimeout(res, t);
});
}