Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
9 changes: 8 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
NEXT_PUBLIC_MODE=default
# Config
PUBLIC_SERVER_URL=http://localhost:4000
PUBLIC_MOCK_DATA=true
SERVER_PORT=4000 # optional, server port (alias: PORT, PUBLIC_SERVER_URL.port) (defaults to 4000 if none are specified)

# Secrets
PUBLIC_X_ANON_KEY=...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

どうでもいいけど、PUPLIC_*はNext.jsのやつ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PUBLIC_ の方が分かりやすいかなと思って Vite の publicPrefix の設定を PUBLIC_ にしました

X_API_KEY=...
43 changes: 6 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
node_modules
/.env

node_modules/

.tool-versions
bun.lockb

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
.next
out

# production
build

# misc
# OS / Dev Env
.DS_Store
*.pem
.direnv

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel
/.direnv

# typescript
# Build Output
dist
*.tsbuildinfo
next-env.d.ts
60 changes: 58 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"packages/*"
],
"scripts": {
"dev": "cd packages/web && bun dev",
"dev:mock": "cd packages/web && bun dev:mock",
"dev": "bun --filter=@packages/{web,server} dev",
"dev:mock": "bun --filter=@packages/{web,server} dev:mock",
"build": "cd packages/web && bun run build",
"check": "bunx biome check .",
"fix": "bunx biome check . --fix"
Expand Down
15 changes: 15 additions & 0 deletions packages/models/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { t } from "elysia";

export type CreateUser = typeof CreateUser.static;
export const CreateUser = t.Object({
name: t.String({
minLength: 1,
maxLength: 255,
}),
});

export type User = typeof User.static;
export const User = t.Object({
id: t.String({ format: "uuid" }),
...CreateUser.properties,
});
17 changes: 17 additions & 0 deletions packages/models/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@packages/models",
"type": "module",
"private": true,
"exports": {
".": "./models.ts"
},
"devDependencies": {
"@types/bun": "^1.2.18"
},
"peerDependencies": {
"typescript": "^5.8.3"
},
"dependencies": {
"elysia": "^1.3.5"
}
}
3 changes: 3 additions & 0 deletions packages/models/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.base.json"
}
15 changes: 0 additions & 15 deletions packages/server/README.md

This file was deleted.

11 changes: 11 additions & 0 deletions packages/server/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { cors } from "@elysiajs/cors";
import { Elysia } from "elysia";
import { usersRouter } from "./router/users.sample";

export const app = new Elysia({
prefix: "/api",
})
.use(cors())
.group("/users", (app) => app.use(usersRouter));

export type App = typeof app;
1 change: 0 additions & 1 deletion packages/server/index.ts

This file was deleted.

17 changes: 14 additions & 3 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
{
"name": "@packages/server",
"module": "index.ts",
"module": "serve.ts",
"type": "module",
"private": true,
"exports": {
".": "./app.ts"
},
"scripts": {
"dev": "bun --env-file=../../.env run --watch ./serve.ts"
},
"devDependencies": {
"@types/bun": "latest"
"@types/bun": "^1.2.18"
},
"peerDependencies": {
"typescript": "^5"
"typescript": "^5.8.3"
},
"dependencies": {
"@elysiajs/cors": "^1.3.3",
"@sinclair/typebox": "^0.34.37",
"elysia": "^1.3.5"
}
}
43 changes: 43 additions & 0 deletions packages/server/router/users.sample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { CreateUser, type User } from "@packages/models";
import { Elysia, status, t } from "elysia";

const users: User[] = [];

export const usersRouter = new Elysia()
.get("/", () => users)
.get("/id", ({ query }) => users.find((user) => user.id === query.id), {
query: t.Object({
id: t.String({
format: "uuid",
}),
}),
})
.post(
"/",
({ body }) => {
users.push({
id: crypto.randomUUID(),
...body,
});
return body;
},
{
body: CreateUser,
},
)
.delete(
"/",
({ query }) => {
const index = users.findIndex((user) => user.id === query.id);
if (index === -1) return status(404, "User not found");
users.splice(index, 1);
return query.id;
},
{
query: t.Object({
id: t.String({
format: "uuid",
}),
}),
},
);
17 changes: 17 additions & 0 deletions packages/server/serve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { app } from "./app.ts";

const port =
process.env.SERVER_PORT ??
process.env.PORT ??
parsePublicServerURL() ??
"4000";

app.listen(port, () =>
console.log(`Server started at http://localhost:${port}`),
);

function parsePublicServerURL() {
if (!process.env.PUBLIC_SERVER_URL) return undefined;
const url = new URL(process.env.PUBLIC_SERVER_URL);
return url.port;
}
Loading