@trigger.dev/cli: Add option to specify the path to the handler function in the dev command
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/cli": patch
|
||||
---
|
||||
|
||||
Add option to specify the path to the handler function in the dev command
|
||||
@@ -42,12 +42,8 @@ program
|
||||
.description(
|
||||
"Tunnel your local Next.js project to Trigger.dev and start running jobs"
|
||||
)
|
||||
.argument("[path]", "The path to the Next.js project", ".")
|
||||
.option(
|
||||
"-p, --port <port>",
|
||||
"The local port your Next.js project is on",
|
||||
"3000"
|
||||
)
|
||||
.argument("[path]", "The path to the project", ".")
|
||||
.option("-p, --port <port>", "The local port your server is on", "3000")
|
||||
.option(
|
||||
"-e, --env-file <name>",
|
||||
"The name of the env file to load",
|
||||
@@ -57,6 +53,11 @@ program
|
||||
"-i, --client-id <name>",
|
||||
"The ID of the client to use for this project. Will use the value from the package.json file if not provided."
|
||||
)
|
||||
.option(
|
||||
"-h, --handler-path <handler path>",
|
||||
"The URI path to the API handler function to use for this project.",
|
||||
"/api/trigger"
|
||||
)
|
||||
.version(getVersion(), "-v, --version", "Display the version number")
|
||||
.action(async (path, options) => {
|
||||
await devCommand(path, options);
|
||||
|
||||
@@ -13,6 +13,7 @@ import dotenv from "dotenv";
|
||||
export const DevCommandOptionsSchema = z.object({
|
||||
port: z.coerce.number(),
|
||||
envFile: z.string(),
|
||||
handlerPath: z.string(),
|
||||
clientId: z.string().optional(),
|
||||
});
|
||||
|
||||
@@ -61,7 +62,11 @@ export async function devCommand(path: string, anyOptions: any) {
|
||||
// Setup tunnel
|
||||
const endpointUrl = await resolveEndpointUrl(apiUrl, options.port);
|
||||
|
||||
const connectingSpinner = ora(`[trigger.dev] Connecting to Trigger.dev...`);
|
||||
const endpointHandlerUrl = `${endpointUrl}${options.handlerPath}`;
|
||||
|
||||
const connectingSpinner = ora(
|
||||
`[trigger.dev] Registering endpoint ${endpointHandlerUrl}...`
|
||||
);
|
||||
|
||||
//refresh function
|
||||
let attemptCount = 0;
|
||||
@@ -84,7 +89,7 @@ export async function devCommand(path: string, anyOptions: any) {
|
||||
const result = await refreshEndpoint(
|
||||
apiClient,
|
||||
refreshedEndpointId ?? endpointId,
|
||||
endpointUrl
|
||||
endpointHandlerUrl
|
||||
);
|
||||
if (result.success) {
|
||||
attemptCount = 0;
|
||||
@@ -245,12 +250,12 @@ async function createTunnel(port: number) {
|
||||
async function refreshEndpoint(
|
||||
apiClient: TriggerApi,
|
||||
endpointId: string,
|
||||
tunnelUrl: string
|
||||
endpointUrl: string
|
||||
) {
|
||||
try {
|
||||
const response = await apiClient.registerEndpoint({
|
||||
id: endpointId,
|
||||
url: `${tunnelUrl}/api/trigger`,
|
||||
url: endpointUrl,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user