@@ -15,7 +15,7 @@ used to pass arbituary data to downstream (or upstream) handlers.
|
||||
|
||||
```ts
|
||||
// routes/_middleware.ts
|
||||
import { MiddlewareHandlerContext } from "../server_deps.ts";
|
||||
import { MiddlewareHandlerContext } from "../deps.server.ts";
|
||||
|
||||
interface State {
|
||||
data: string;
|
||||
|
||||
@@ -22,7 +22,7 @@ Let's look at a basic route that returns a plain text string:
|
||||
```tsx
|
||||
// routes/plain.tsx
|
||||
|
||||
import { HandlerContext, Handlers } from "../server_deps.ts";
|
||||
import { HandlerContext, Handlers } from "../deps.server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(ctx: HandlerContext) {
|
||||
@@ -43,7 +43,7 @@ Now, let's render some HTML using the route component. Another example:
|
||||
// routes/html.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, PageProps } from "../client_deps.ts";
|
||||
import { h, PageProps } from "../deps.client.ts";
|
||||
|
||||
export default function Page(props: PageProps) {
|
||||
return <div>You are on the page '{props.url.href}'.</div>;
|
||||
@@ -65,8 +65,8 @@ response after rendering the page component.
|
||||
// routes/html.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, PageProps } from "../client_deps.ts";
|
||||
import { HandlerContext, Handlers } from "../server_deps.ts";
|
||||
import { h, PageProps } from "../deps.client.ts";
|
||||
import { HandlerContext, Handlers } from "../deps.server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(ctx: HandlerContext) {
|
||||
|
||||
@@ -31,7 +31,7 @@ Here is an example of an island component that counts down to a specific time.
|
||||
// islands/Countdown.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, useEffect, useMemo, useState } from "../client_deps.ts";
|
||||
import { h, useEffect, useMemo, useState } from "../deps.client.ts";
|
||||
|
||||
const timeFmt = new Intl.RelativeTimeFormat("en-US");
|
||||
|
||||
@@ -73,7 +73,7 @@ client with the correct props:
|
||||
// routes/countdown.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h } from "../client_deps.ts";
|
||||
import { h } from "../deps.client.ts";
|
||||
import { Countdown } from "../islands/Countdown.tsx";
|
||||
|
||||
export default function Page() {
|
||||
|
||||
@@ -29,11 +29,11 @@ files, only two are strictly necessary for a fresh project:
|
||||
In addition to these two files, two other files are created that manage
|
||||
dependencies:
|
||||
|
||||
- **`client_deps.ts`**: This file contains dependencies that you need on the
|
||||
- **`deps.client.ts`**: This file contains dependencies that you need on the
|
||||
client, and possibly also on the server. It should be assumed that all of the
|
||||
dependencies referenced by this file will be shipped to the client. By
|
||||
default, it just re-exports the `fresh` runtime.
|
||||
- **`server_deps.ts`**: This file contains dependencies that are only used on
|
||||
- **`deps.server.ts`**: This file contains dependencies that are only used on
|
||||
the server. These are often things like database drivers, API clients, or
|
||||
other code that should only be executed on the server. This file should never
|
||||
be referenced by modules that might be shipped to the client. By default this
|
||||
|
||||
@@ -38,7 +38,7 @@ This is done with JSX.
|
||||
// routes/about.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h } from "../client_deps.ts";
|
||||
import { h } from "../deps.client.ts";
|
||||
|
||||
export default function AboutPage() {
|
||||
return (
|
||||
|
||||
@@ -31,7 +31,7 @@ then adds a custom header to the response before returning it:
|
||||
// routes/about.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, Handlers } from "../client_deps.ts";
|
||||
import { h, Handlers } from "../deps.client.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(req, ctx) {
|
||||
@@ -58,7 +58,7 @@ response:
|
||||
```ts
|
||||
// routes/api/random-uuid.ts
|
||||
|
||||
import { Handlers } from "../client_deps.ts";
|
||||
import { Handlers } from "../deps.client.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(req) {
|
||||
|
||||
@@ -28,7 +28,7 @@ as arguments in it's `props` object though.
|
||||
// routes/greet/[name].tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, PageProps } from "../../client_deps.ts";
|
||||
import { h, PageProps } from "../../deps.client.ts";
|
||||
|
||||
export default function AboutPage(props: PageProps) {
|
||||
const { name } = props.params;
|
||||
|
||||
@@ -24,8 +24,8 @@ renders it in a page component.
|
||||
// routes/github/[username].tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, PageProps } from "../../client_deps.ts";
|
||||
import { Handlers } from "../../server_deps.ts";
|
||||
import { h, PageProps } from "../../deps.client.ts";
|
||||
import { Handlers } from "../../deps.server.ts";
|
||||
|
||||
interface User {
|
||||
login: string;
|
||||
|
||||
@@ -33,8 +33,8 @@ server side:
|
||||
// routes/search.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, PageProps } from "../../client_deps.ts";
|
||||
import { Handlers } from "../../server_deps.ts";
|
||||
import { h, PageProps } from "../../deps.client.ts";
|
||||
import { Handlers } from "../../deps.server.ts";
|
||||
|
||||
const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"];
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ your application. All routes can act as both API endpoints and dynamic HTML
|
||||
pages. More info about how the `routes` subdirectory works can be found on the
|
||||
[file system routing](./file-system-routing.md) page.
|
||||
|
||||
Finally there is a `client_deps.ts` and `server_deps.ts`. These files are the
|
||||
central location for all external imports. The `client_deps.ts` file is used for
|
||||
Finally there is a `deps.client.ts` and `deps.server.ts`. These files are the
|
||||
central location for all external imports. The `deps.client.ts` file is used for
|
||||
runtime dependencies (ones that are used both in routes and islands), and the
|
||||
`server_deps.ts` file is used for server only dependencies (for example ones
|
||||
`deps.server.ts` file is used for server only dependencies (for example ones
|
||||
used in API routes or middleware).
|
||||
|
||||
Reference in New Issue
Block a user