Packages: +96
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 96, reused 95, downloaded 1, added 96, done
? Where would you like to create your Turborepo? mono
? Which package manager do you want to use? pnpm
>>> Creating a new Turborepo with:
Application packages
- apps/docs
- apps/web
Library packages
- packages/eslint-config
- packages/typescript-config
- packages/ui
>>> Success! Created your Turborepo at mono
To get started:
- Change to the directory: cd mono
- Enable Remote Caching (recommended): pnpm dlx turbo login
- Learn more: https://turbo.build/repo/remote-cache
- Run commands with Turborepo:
- pnpm run build: Build all apps and packages
- pnpm run dev: Develop all apps and packages
- pnpm run lint: Lint all apps and packages
- Run a command twice to hit cache
pnpm create hono@latest
.../1918cb4e015-12ef2 | +1 +
.../1918cb4e015-12ef2 | Progress: resolved 1, reused 1, downloaded 0, added 1, done
create-hono version 0.12.0
? Target directory api
? Which template do you want to use? cloudflare-workers
✔ Cloning the template
? Do you want to install project dependencies? yes
? Which package manager do you want to use? pnpm
✔ Installing project dependencies
🎉 Copied project files
Get started with: cd api
import { Hono } from "hono";
import hoge from "./hoge";
import { cors } from "hono/cors";
const app = new Hono();
app.use('/*', cors({
origin: ['http://localhost:3000'], // フロントエンドのURLを指定
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowHeaders: ['Content-Type', 'Authorization'],
exposeHeaders: ['Content-Length'],
maxAge: 600,
credentials: true,
}))
const route = app.route("/hoge", hoge);
export type AppType = typeof route;
export default app;
"name": "@yutanakano/api",
"version": "0.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/yutanakano/mono.git",
"directory": "packages/api"
},
"scripts": {
...
"build": "tsc",
...
},
...
"use client";
import type { AppType } from "@yutanakano/api";
import { hc } from "hono/client";
import { useEffect, useState } from "react";
export default function RPC() {
const client = hc<AppType>("http://localhost:8787");
const [message, setMessage] = useState("hello world");
const fetchGet = async () => {
const res = await client.hoge.$get();
if (res.ok) {
const data = await res.json();
setMessage(data.message);
} else {
setMessage("error");
}
};
useEffect(() => {
fetchGet();
}, []);
return <p>{message}</p>;
}