Skip to content

Commit

Permalink
Merge pull request #1 from chedakr/feature/login-api
Browse files Browse the repository at this point in the history
기본 로그인 API 구현 및 페이지 추가
  • Loading branch information
Xvezda authored Apr 16, 2024
2 parents 5aefd5f + e225d65 commit 4fe5c68
Show file tree
Hide file tree
Showing 37 changed files with 3,129 additions and 266 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Simple workflow for deploying static content to GitHub Pages
name: Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm --filter=web run build
- name: Deploy to GitHub Pages
run: pnpm --filter=web run deploy
9 changes: 9 additions & 0 deletions apps/api/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
schema: "./src/db/schema.ts",
out: "./drizzle",
driver: 'd1',
verbose: true,
strict: true,
})
17 changes: 17 additions & 0 deletions apps/api/drizzle/0000_stale_doorman.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE `users` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`user_id` text NOT NULL,
`user_name` text NOT NULL,
`user_image` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
`access_token` text,
`refresh_token` text,
`token_type` text,
`expire_at` integer
);
--> statement-breakpoint
CREATE UNIQUE INDEX `idx_users_user_id` ON `users` (`user_id`);--> statement-breakpoint
CREATE INDEX `idx_users_user_name` ON `users` (`user_name`);--> statement-breakpoint
CREATE INDEX `idx_users_created_at` ON `users` (`created_at`);--> statement-breakpoint
CREATE INDEX `idx_users_updated_at` ON `users` (`updated_at`);
122 changes: 122 additions & 0 deletions apps/api/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"version": "5",
"dialect": "sqlite",
"id": "adb7d579-e149-4d0e-9c32-f5c0f77d5f8a",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_name": {
"name": "user_name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_image": {
"name": "user_image",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"access_token": {
"name": "access_token",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"refresh_token": {
"name": "refresh_token",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"token_type": {
"name": "token_type",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"expire_at": {
"name": "expire_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"idx_users_user_id": {
"name": "idx_users_user_id",
"columns": [
"user_id"
],
"isUnique": true
},
"idx_users_user_name": {
"name": "idx_users_user_name",
"columns": [
"user_name"
],
"isUnique": false
},
"idx_users_created_at": {
"name": "idx_users_created_at",
"columns": [
"created_at"
],
"isUnique": false
},
"idx_users_updated_at": {
"name": "idx_users_updated_at",
"columns": [
"updated_at"
],
"isUnique": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
13 changes: 13 additions & 0 deletions apps/api/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1713153522431,
"tag": "0000_stale_doorman",
"breakpoints": true
}
]
}
6 changes: 6 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.1.0",
"@cloudflare/workers-types": "^4.20240405.0",
"drizzle-kit": "^0.20.14",
"typescript": "^5.0.4",
"vitest": "1.3.0",
"wrangler": "^3.0.0"
},
"dependencies": {
"@libsql/client": "^0.6.0",
"drizzle-orm": "^0.30.8",
"hono": "^4.2.4"
}
}
21 changes: 21 additions & 0 deletions apps/api/src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { sqliteTable, integer, text, uniqueIndex, index } from 'drizzle-orm/sqlite-core';

export const users = sqliteTable('users', {
id: integer('id').primaryKey({ autoIncrement: true }),
userId: text('user_id').notNull(),
userName: text('user_name').notNull(),
userImage: text('user_image'),
createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).notNull(),
accessToken: text('access_token'),
refreshToken: text('refresh_token'),
tokenType: text('token_type'),
expireAt: integer('expire_at', { mode: 'timestamp_ms' }),
}, (table) => {
return {
idxUserId: uniqueIndex('idx_users_user_id').on(table.userId),
idxUserName: index('idx_users_user_name').on(table.userName),
idxCreatedAt: index('idx_users_created_at').on(table.createdAt),
idxUpdatedAt: index('idx_users_updated_at').on(table.updatedAt),
};
});
57 changes: 28 additions & 29 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import auth from './services/auth/v1/route';
import { Env } from '@/typings';

export interface Env {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
// MY_KV_NAMESPACE: KVNamespace;
//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
//
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
// MY_SERVICE: Fetcher;
//
// Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
// MY_QUEUE: Queue;
}
const app = new Hono<{ Bindings: Env }>();

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
return new Response('Hello World!');
app.use('*', cors({
origin: (origin, c) => {
if (c.env.DEV) {
return origin;
}

try {
const originUrl = new URL(origin);
if (originUrl.hostname === 'cheda.kr' || originUrl.hostname.endsWith('.cheda.kr')) {
return origin;
}
} catch (e) {}

return origin;
},
};
}));

app.get('/', async (c) => {
return c.json({ message: c.env.DEV ? 'Hello, World!' : 'OK' });
});

app.route('/services/auth/v1', auth);

export default app;
Loading

0 comments on commit 4fe5c68

Please sign in to comment.