Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
be74273
updated the @trigger.dev/astro package to support typescript
Chigala Sep 10, 2023
1ce8bb9
set up a example astro project
Chigala Sep 10, 2023
0d2da94
docs: manual setup of Trigger.dev in an Astro project
Chigala Sep 10, 2023
d6651b8
doc: updated the manual setup docs for astro
Chigala Sep 11, 2023
b8a26f8
updated the webapp onboarding for astro
Chigala Sep 11, 2023
af24e18
cleaned up the example astro project
Chigala Sep 11, 2023
aba11b3
Merge branch 'main' into feat/astro-support
Chigala Sep 12, 2023
0607450
removed next from dependency 😅
Chigala Sep 12, 2023
28bc98c
updated the readme
Chigala Sep 12, 2023
bd19e87
moved trigger.ts file and job folder to src directory
Chigala Sep 12, 2023
d999110
created a .env.example file
Chigala Sep 12, 2023
546551a
updated tsconfig
Chigala Sep 12, 2023
c85f953
updated to use aliases
Chigala Sep 12, 2023
80053d3
updated package.json
Chigala Sep 12, 2023
6e088d0
updated the astro onboarding page
Chigala Sep 12, 2023
0e15665
updated the manual installation guide for astro
Chigala Sep 12, 2023
4f4c95b
updated to use alias
Chigala Sep 12, 2023
5a96e10
added astro as a dev dependency
Chigala Sep 12, 2023
27d89b8
Merge branch 'main' into feat/astro-support
matt-aitken Sep 13, 2023
8d4b857
Remove extra comma I left in
matt-aitken Sep 13, 2023
ef6c2f3
Changed Object.create() to a Record, so we have some type safety
matt-aitken Sep 13, 2023
fff0e5f
Added the localhost URL to the API in the Astro example
matt-aitken Sep 13, 2023
2780a2b
Added the TRIGGER_API_URL to the trigger client in the example
matt-aitken Sep 13, 2023
9a6ed8f
Added the CLI dev dependency to the Astro example
matt-aitken Sep 13, 2023
61dce58
Update the running instructions to be closer to Remix's
matt-aitken Sep 13, 2023
9aebebb
Create friendly-carpets-collect.md
matt-aitken Sep 13, 2023
95cdc4c
Fix bad package name for Astro
matt-aitken Sep 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/friendly-carpets-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/astro": patch
---

The first release of Astro support
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function FrameworkSelector() {
<FrameworkLink to={projectSetupRedwoodPath(organization, project)}>
<RedwoodLogo className="w-44" />
</FrameworkLink>
<FrameworkLink to={projectSetupAstroPath(organization, project)}>
<FrameworkLink to={projectSetupAstroPath(organization, project)} supported>
<AstroLogo className="w-32" />
</FrameworkLink>
<FrameworkLink to={projectSetupNuxtPath(organization, project)}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,119 @@
import { AstroLogo } from "~/assets/logos/AstroLogo";
import { FrameworkComingSoon } from "~/components/frameworks/FrameworkComingSoon";
import { ChatBubbleLeftRightIcon, Squares2X2Icon } from "@heroicons/react/20/solid";
import invariant from "tiny-invariant";
import { Feedback } from "~/components/Feedback";
import { PageGradient } from "~/components/PageGradient";
import { InitCommand, RunDevCommand, TriggerDevStep } from "~/components/SetupCommands";
import { StepContentContainer } from "~/components/StepContentContainer";
import { InlineCode } from "~/components/code/InlineCode";
import { BreadcrumbLink } from "~/components/navigation/NavBar";
import { Button, LinkButton } from "~/components/primitives/Buttons";
import {
ClientTabs,
ClientTabsContent,
ClientTabsList,
ClientTabsTrigger,
} from "~/components/primitives/ClientTabs";
import { ClipboardField } from "~/components/primitives/ClipboardField";
import { Header1 } from "~/components/primitives/Headers";
import { NamedIcon } from "~/components/primitives/NamedIcon";
import { Paragraph } from "~/components/primitives/Paragraph";
import { StepNumber } from "~/components/primitives/StepNumber";
import { useAppOrigin } from "~/hooks/useAppOrigin";
import { useProjectSetupComplete } from "~/hooks/useProjectSetupComplete";
import { useDevEnvironment } from "~/hooks/useEnvironments";
import { useOrganization } from "~/hooks/useOrganizations";
import { useProject } from "~/hooks/useProject";
import { Handle } from "~/utils/handle";
import { trimTrailingSlash } from "~/utils/pathBuilder";
import { projectSetupPath, trimTrailingSlash } from "~/utils/pathBuilder";
import { Callout } from "~/components/primitives/Callout";
import { Badge } from "~/components/primitives/Badge";

export const handle: Handle = {
breadcrumb: (match) => <BreadcrumbLink to={trimTrailingSlash(match.pathname)} title="Astro" />,
};

export default function Page() {
export default function SetUpAstro() {
const organization = useOrganization();
const project = useProject();
useProjectSetupComplete();
const devEnvironment = useDevEnvironment();
invariant(devEnvironment, "Dev environment must be defined");
return (
<FrameworkComingSoon
frameworkName="Astro"
githubIssueUrl="https://github.com/triggerdotdev/trigger.dev/issues/452"
githubIssueNumber={452}
>
<AstroLogo className="w-56" />
</FrameworkComingSoon>
<PageGradient>
<div className="mx-auto max-w-3xl">
<div className="flex items-center justify-between">
<Header1 spacing className="text-bright">
Get setup in 5 minutes
</Header1>
<div className="flex items-center gap-2">
<LinkButton
to={projectSetupPath(organization, project)}
variant="tertiary/small"
LeadingIcon={Squares2X2Icon}
>
Choose a different framework
</LinkButton>
<Feedback
button={
<Button variant="tertiary/small" LeadingIcon={ChatBubbleLeftRightIcon}>
I'm stuck!
</Button>
}
defaultValue="help"
/>
</div>
</div>
<div>
<Callout
variant={"info"}
to="https://github.com/triggerdotdev/trigger.dev/discussions/430"
className="mb-8"
>
Trigger.dev has full support for serverless. We will be adding support for long-running
servers soon.
</Callout>
<div>
<StepNumber
stepNumber="1"
title="Follow the steps from the Astro manual installation guide"
/>
<StepContentContainer className="flex flex-col gap-2">
<Paragraph className="mt-2">Copy your server API Key to your clipboard:</Paragraph>
<div className="mb-2 flex w-full items-center justify-between">
<ClipboardField
secure
className="w-fit"
value={devEnvironment.apiKey}
variant={"secondary/medium"}
icon={<Badge variant="outline">Server</Badge>}
/>
</div>
<Paragraph>Now follow this guide:</Paragraph>
<LinkButton
to="https://trigger.dev/docs/documentation/guides/manual/astro"
variant="primary/medium"
TrailingIcon="external-link"
>
Manual installation guide
</LinkButton>
<div className="flex items-start justify-start gap-2"></div>
</StepContentContainer>
<StepNumber stepNumber="2" title="Run your Astro app" />
<StepContentContainer>
<RunDevCommand />
</StepContentContainer>
<StepNumber stepNumber="3" title="Run the CLI 'dev' command" />
<StepContentContainer>
<TriggerDevStep />
</StepContentContainer>
<StepNumber stepNumber="6" title="Wait for Jobs" displaySpinner />
<StepContentContainer>
<Paragraph>This page will automatically refresh.</Paragraph>
</StepContentContainer>
</div>
</div>
</div>
</PageGradient>
);
}
249 changes: 248 additions & 1 deletion docs/_snippets/manual-setup-astro.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,248 @@
We're in the process of building support for the Astro framework. You can follow along with progress or contribute via [this GitHub issue](https://github.com/triggerdotdev/trigger.dev/issues).
## Install Required Packages

To begin, install the necessary packages in your Astro project directory. You can choose one of the following package managers:

<CodeGroup>

```bash npm
npm i @trigger.dev/sdk @trigger.dev/astro
```

```bash pnpm
pnpm install @trigger.dev/sdk @trigger.dev/astro
```

```bash yarn
yarn add @trigger.dev/sdk @trigger.dev/astro
```

</CodeGroup>

## Obtaining the Development API Key

To locate your development API key, login to the [Trigger.dev
dashboard](https://cloud.trigger.dev) and select the Project you want to
connect to. Then click on the Environments & API Keys tab in the left menu.
You can copy your development API Key from the field at the top of this page.
(Your development key will start with `tr_dev_`).

## Adding Environment Variables

Create a `.env` file at the root of your project and include your Trigger API key and URL like this:

```bash
TRIGGER_API_KEY=ENTER_YOUR_DEVELOPMENT_API_KEY_HERE
TRIGGER_API_URL=https://cloud.trigger.dev
```

Replace `ENTER_YOUR_DEVELOPMENT_API_KEY_HERE` with the actual API key obtained from the previous step.

## Configuring the Trigger Client

To set up the Trigger Client for your project, follow these steps:

1. **Create Configuration File:**

In your project directory, create a configuration file named `trigger.ts` or `trigger.js`, depending on whether your project uses TypeScript (`.ts`) or JavaScript (`.js`).

2. **Choose Directory:**

Depending on your project structure, choose the appropriate directory for the configuration file. If your project uses a `src` directory, create the file within it or Otherwise, create it directly in the project root.

3. **Add Configuration Code:**

Open the configuration file you created and add the following code:

```typescript src/trigger.(ts/js)
// trigger.ts (for TypeScript) or trigger.js (for JavaScript)

import { TriggerClient } from "@trigger.dev/sdk";

export const client = new TriggerClient({
id: "my-app",
apiKey: process.env.TRIGGER_API_KEY,
apiUrl: process.env.TRIGGER_API_URL,
});
```

Replace **"my-app"** with an appropriate identifier for your project. The **apiKey** and **apiUrl** are obtained from the environment variables you set earlier.

4. **File Location:**

- You can save the file within the **src** directory or in the project rooot.

**Example Directory Structure with src:**

```
project-root/
├── src/
├── trigger.ts
├── other files...
```

**Example Directory Structure without src:**

```
project-root/
├── trigger.ts
├── other files...
```

By following these steps, you'll configure the Trigger Client to work with your project, regardless of whether you have a separate **src** directory and whether you're using TypeScript or JavaScript files.

## update the astro.config file to enable ssr

- You need to enable ssr to use API endpoints that would be in the `pages/api` folder

```typescript astro.config.mjs
import { defineConfig } from "astro/config";

export default defineConfig({
output: "server",
});
```

## Creating the API Route

To establish an API route for interacting with Trigger.dev, follow these steps based on your project's file type and structure

1. Create a new file named `trigger.(ts/js)` within the `pages/api/` directory.
2. Add the following code to `trigger.(ts/js)`:

```typescript api/trigger.ts/js
import { createAstroRoute } from "@trigger.dev/astro";
import { client } from "@/trigger";

//import your jobs
import "@/jobs";

export const { POST } = createAstroRoute(client);
```

## Creating the Example Job

1. Create a folder named `Jobs` alongside your `pages` directory
2. Inside the `Jobs` folder, add two files named `example.(ts/js)` and `index.(ts/js)`.

<CodeGroup>

```typescript example.(ts/js)
import { eventTrigger } from "@trigger.dev/sdk";
import { client } from "@/trigger";

// your first job
client.defineJob({
id: "example-job",
name: "Example Job",
version: "0.0.1",
trigger: eventTrigger({
name: "example.event",
}),
run: async (payload, io, ctx) => {
await io.logger.info("Hello world!", { payload });

return {
message: "Hello world!",
};
},
});
```

```typescript index.ts/index.(ts/js)
// import all your job files here

export * from "./examples";
```

</CodeGroup>

## Additonal Job Definitions

You can define more job definitions by creating additional files in the `Jobs` folder and exporting them in `index` file.

For example, in `index.(ts/js)`, you can export other job files like this:

```typescript
// import all your job files here

export * from "./examples";
export * from "./other-job-file";
```

## Adding Configuration to `package.json`

Inside the `package.json` file, add the following configuration under the root object:

```json
"trigger.dev": {
"endpointId": "my-app"
}
```

Your `package.json` file might look something like this:

```json
{
"name": "my-app",
"version": "1.0.0",
"dependencies": {
// ... other dependencies
},
"trigger.dev": {
"endpointId": "my-app"
}
}
```

Replace **"my-app"** with the appropriate identifier you used during the step for creating the Trigger Client.

## Running

### Run your Astro app

Run your Astro app locally, like you normally would. For example:

<CodeGroup>

```bash npm
npm run dev
```

```bash pnpm
pnpm run dev
```

```bash yarn
yarn run dev
```

</CodeGroup>

### Run the CLI 'dev' command

In a **_separate terminal window or tab_** run:

<CodeGroup>

```bash npm
npx @trigger.dev/cli@latest dev
```

```bash pnpm
pnpm dlx @trigger.dev/cli@latest dev
```

```bash yarn
yarn dlx @trigger.dev/cli@latest dev
```

</CodeGroup>
<br />
<Note>
You can optionally pass the port if you're not running on 3000 by adding
`--port 4321` to the end
</Note>
<Note>
You can optionally pass the hostname if you're not running on localhost by adding
`--hostname <host>`. Example, in case your Astro app is running on 0.0.0.0: `--hostname 0.0.0.0`.
</Note>
Loading