Skip to content

Commit

Permalink
rename phoenix
Browse files Browse the repository at this point in the history
  • Loading branch information
dev committed Dec 26, 2023
1 parent 623d08b commit e0f0535
Show file tree
Hide file tree
Showing 131 changed files with 840 additions and 575 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ on:

jobs:

phoenix:
cloudflarebook.com:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cloudflarebook.com
steps:
- uses: actions/checkout@v3

Expand Down
16 changes: 0 additions & 16 deletions Makefile

This file was deleted.

16 changes: 16 additions & 0 deletions cloudflarebook.com/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: install_ci
install_ci:
npm ci --no-scripts --ignore-scripts


.PHONY: test
test:
cd api && npm run test
cd blog && npm run test
cd webapp && npm run test

.PHONY: deploy
deploy:
cd api && npm run deploy
cd blog && npm run deploy
cd webapp && npm run deploy
6 changes: 4 additions & 2 deletions docs/phoenix.md → cloudflarebook.com/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Phoenix
# cloudflarebook.com

This folder contains the code running at [cloudflarebook.com](https://cloudflarebook.com).

## Architecture

![Phoenix Architecture](./phoenix_architecture.png)
![cloudflarebook.com Architecture](./docs/architecture.png)


## Deploy in your Cloudflare account
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DATABASE_URL="xxx"
# JWT_SECRET should be at least 256 bits. Use `openssl rand -base64 32` to generate it
JWT_SECRET="xxx"
# e.g. phoenix.blog
# e.g. mywebsite.blog
BLOGS_ROOT_DOMAIN="xxx"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "phoenix-api",
"name": "@cloudflarebook.com/api",
"author": "https://kerkour.com",
"version": "0.1.0",
"private": true,
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions phoenix-api/src/app.ts → cloudflarebook.com/api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hono } from 'hono';
import { ErrorCode, NotFoundError, PermissionDeniedError, formatZodError } from '@phoenix/core/errors';
import { ApiError, ApiResponse, Routes } from '@phoenix/core/api';
import { requestIdMiddleware } from '@phoenix/core/middlewares';
import { ErrorCode, NotFoundError, PermissionDeniedError, formatZodError } from '@cloudflarebook.com/core/errors';
import { ApiError, ApiResponse, Routes } from '@cloudflarebook.com/core/api';
import { requestIdMiddleware } from '@cloudflarebook.com/core/middlewares';
import { Bindings, Variables } from './hono_bindings';
import { ZodError } from 'zod';
import { createPage } from './blogs/create_page';
Expand Down Expand Up @@ -38,7 +38,7 @@ app.use('*', requestIdMiddleware());

// API
app.get('/', (ctx) => {
return ctx.json({ message: 'Hello Phoenix!' });
return ctx.json({ message: 'Hello World!' });
});

app.post(Routes.Signup, signup);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { uuidv7 } from "@phoenix/uuidv7";
import { uuidv7 } from "@cloudflarebook.com/uuidv7";
import { checkAuth, checkIsAdmin, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { CreateBlogInputValidator } from "@phoenix/core/api";
import { Blog } from "@phoenix/core/entities";
import { CreateBlogInputValidator } from "@cloudflarebook.com/core/api";
import { Blog } from "@cloudflarebook.com/core/entities";
import { Context } from "../hono_bindings";

export async function createBlog(ctx: Context): Promise<Response> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { checkAuth, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { NotFoundError } from "@phoenix/core/errors";
import { uuidv7 } from "@phoenix/uuidv7";
import { NotFoundError } from "@cloudflarebook.com/core/errors";
import { uuidv7 } from "@cloudflarebook.com/uuidv7";
import { checkIsAdmin } from "../utils";
import { CreatePageInputValidator } from "@phoenix/core/api";
import { Blog, Page } from "@phoenix/core/entities";
import { CreatePageInputValidator } from "@cloudflarebook.com/core/api";
import { Blog, Page } from "@cloudflarebook.com/core/entities";
import { Context } from "../hono_bindings";
import { parseBlogFromDB } from "./utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context } from "../hono_bindings";
import { checkAuth, checkIsAdmin, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { DeleteBlogInputValidator } from "@phoenix/core/api";
import { DeleteBlogInputValidator } from "@cloudflarebook.com/core/api";

export async function deleteBlog(ctx: Context): Promise<Response> {
const userId = await checkAuth(ctx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NotFoundError } from "@phoenix/core/errors";
import { NotFoundError } from "@cloudflarebook.com/core/errors";
import { Context } from "../hono_bindings";
import { checkAuth, checkIsAdmin, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { DeletePageInputValidator } from "@phoenix/core/api";
import { Page, PageValidator } from "@phoenix/core/entities";
import { DeletePageInputValidator } from "@cloudflarebook.com/core/api";
import { Page, PageValidator } from "@cloudflarebook.com/core/entities";

export async function deletePage(ctx: Context): Promise<Response> {
const userId = await checkAuth(ctx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context } from "../hono_bindings";
import { checkAuth, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { NotFoundError } from "@phoenix/core/errors";
import { GetBlogInputValidator } from "@phoenix/core/api";
import { NotFoundError } from "@cloudflarebook.com/core/errors";
import { GetBlogInputValidator } from "@cloudflarebook.com/core/api";
import { parseBlogFromDB } from "./utils";

export async function getBlog(ctx: Context): Promise<Response> {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Context } from "../hono_bindings";
import { checkAuth, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { NotFoundError } from "@phoenix/core/errors";
import { GetPageInputValidator } from "@phoenix/core/api";
import { Page, PageValidator } from "@phoenix/core/entities";
import { NotFoundError } from "@cloudflarebook.com/core/errors";
import { GetPageInputValidator } from "@cloudflarebook.com/core/api";
import { Page, PageValidator } from "@cloudflarebook.com/core/entities";

export async function getPage(ctx: Context): Promise<Response> {
await checkAuth(ctx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context } from "../hono_bindings";
import { checkAuth, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { GetPagesInputValidator } from "@phoenix/core/api";
import { PageValidator } from "@phoenix/core/entities";
import { GetPagesInputValidator } from "@cloudflarebook.com/core/api";
import { PageValidator } from "@cloudflarebook.com/core/entities";

export async function getPages(ctx: Context): Promise<Response> {
await checkAuth(ctx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from "../hono_bindings";
import { NotFoundError } from "@phoenix/core/errors";
import { NotFoundError } from "@cloudflarebook.com/core/errors";
import { parseBlogFromDB } from "./utils";
import { sendApiResponse } from "../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context } from "../hono_bindings";
import { NotFoundError } from "@phoenix/core/errors";
import { PageValidator } from "@phoenix/core/entities";
import { NotFoundError } from "@cloudflarebook.com/core/errors";
import { PageValidator } from "@cloudflarebook.com/core/entities";
import { sendApiResponse } from "../utils";

export async function headlessGetPage(ctx: Context): Promise<Response> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from "../hono_bindings";
import { PageValidator } from "@phoenix/core/entities";
import { PageValidator } from "@cloudflarebook.com/core/entities";
import { sendApiResponse } from "../utils";

export async function headlessGetPosts(ctx: Context): Promise<Response> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context } from "../hono_bindings";
import { checkAuth, checkIsAdmin, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { NotFoundError } from "@phoenix/core/errors";
import { UpdateBlogInputValidator } from "@phoenix/core/api";
import { NotFoundError } from "@cloudflarebook.com/core/errors";
import { UpdateBlogInputValidator } from "@cloudflarebook.com/core/api";
import { parseBlogFromDB } from "./utils";

export async function updateBlog(ctx: Context): Promise<Response> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Context } from "../hono_bindings";
import { checkAuth, checkIsAdmin, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { NotFoundError } from "@phoenix/core/errors";
import { UpdatePageInputValidator } from "@phoenix/core/api";
import { PageValidator } from "@phoenix/core/entities";
import { NotFoundError } from "@cloudflarebook.com/core/errors";
import { UpdatePageInputValidator } from "@cloudflarebook.com/core/api";
import { PageValidator } from "@cloudflarebook.com/core/entities";

export async function updatePage(ctx: Context): Promise<Response> {
const userId = await checkAuth(ctx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Blog, BlogValidator } from "@phoenix/core/entities";
import { Blog, BlogValidator } from "@cloudflarebook.com/core/entities";

export function parseBlogFromDB(blog: any): Blog {
blog.navigation = JSON.parse(blog.navigation);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { setCookie } from "hono/cookie";
import { Context } from "../hono_bindings";
import jwt from "@phoenix/jwt";
import { NotFoundError, PermissionDeniedError } from "@phoenix/core/errors";
import jwt from "@cloudflarebook.com/jwt";
import { NotFoundError, PermissionDeniedError } from "@cloudflarebook.com/core/errors";
import { base64ToBuffer, hashPassword, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { LoginInputValidator, convertUser } from "@phoenix/core/api";
import { UserValidator } from "@phoenix/core/entities";
import { LoginInputValidator, convertUser } from "@cloudflarebook.com/core/api";
import { UserValidator } from "@cloudflarebook.com/core/entities";

export async function login(ctx: Context): Promise<Response> {
const apiInput = await parseAndValidateApiInput(ctx, LoginInputValidator);
Expand Down Expand Up @@ -33,7 +33,7 @@ export async function login(ctx: Context): Promise<Response> {
}, ctx.env.JWT_SECRET);

// in a real-world application you want to set the httpOnly flag as true
setCookie(ctx, 'phoenix_session', authToken,
setCookie(ctx, 'cloudflarebook.com_session', authToken,
{ httpOnly: false, expires: expiresAt, sameSite: 'Lax', secure: true, path: '/' },
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { bufferToBase64, hashPassword, parseAndValidateApiInput, sendApiResponse } from "../utils";
import { uuidv7 } from "@phoenix/uuidv7";
import { PermissionDeniedError } from "@phoenix/core/errors";
import { User } from "@phoenix/core/entities";
import { SignupInputValidator, convertUser } from "@phoenix/core/api";
import { uuidv7 } from "@cloudflarebook.com/uuidv7";
import { PermissionDeniedError } from "@cloudflarebook.com/core/errors";
import { User } from "@cloudflarebook.com/core/entities";
import { SignupInputValidator, convertUser } from "@cloudflarebook.com/core/api";
import { Context } from "../hono_bindings";
import jwt from "@phoenix/jwt";
import jwt from "@cloudflarebook.com/jwt";
import { setCookie } from "hono/cookie";

export async function signup(ctx: Context): Promise<Response> {
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function signup(ctx: Context): Promise<Response> {
}, ctx.env.JWT_SECRET);

// in a real-world application you want to set the httpOnly flag as true
setCookie(ctx, 'phoenix_session', authToken,
setCookie(ctx, 'cloudflarebook.com_session', authToken,
{ httpOnly: false, expires: expiresAt, sameSite: 'Lax', secure: true, path: '/' },
);

Expand Down
10 changes: 5 additions & 5 deletions phoenix-api/src/utils.ts → cloudflarebook.com/api/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Context } from "./hono_bindings";
import { getCookie } from "hono/cookie";
import { InvalidArgumentError, NotFoundError, PermissionDeniedError } from "@phoenix/core/errors";
import jwt from "@phoenix/jwt";
import { InvalidArgumentError, NotFoundError, PermissionDeniedError } from "@cloudflarebook.com/core/errors";
import jwt from "@cloudflarebook.com/jwt";
import { ZodSchema } from "zod";
import { UserValidator } from "@phoenix/core/entities";
import { ApiResponse } from "@phoenix/core/api_client";
import { UserValidator } from "@cloudflarebook.com/core/entities";
import { ApiResponse } from "@cloudflarebook.com/core/api_client";

export function sendApiResponse<T>(ctx: Context, data: T, status = 200): Response {
const body: ApiResponse<T> = {
Expand Down Expand Up @@ -62,7 +62,7 @@ export function base64ToBuffer(hash: string): ArrayBuffer {
}

export async function checkAuth(ctx: Context): Promise<string> {
const authCookie = getCookie(ctx, 'phoenix_session');
const authCookie = getCookie(ctx, 'cloudflarebook_session');
if (!authCookie) {
throw new PermissionDeniedError('authentication is required');
}
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions cloudflarebook.com/api/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name = "cloudflarebook-api"
main = "src/app.ts"
compatibility_date = "2023-09-18"


vars = []

r2_buckets = [
{ binding = "r2", bucket_name = "cloudflarebook-dev" }
]

d1_databases = [
{ binding = "DB", database_name = "cloudflarebook", database_id = "2a9779e5-3223-4640-9fe4-6992a08a142c" }
]

[placement]
mode = "smart"

[env.production]

r2_buckets = [
{ binding = "r2", bucket_name = "cloudflarebook" }
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "phoenix-blog",
"name": "@cloudflarebook.com/blog",
"author": "https://kerkour.com",
"version": "0.1.0",
"private": true,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Context as HonoContext } from "hono";

export type Bindings = {
api: Fetcher;
phoenix_storage: R2Bucket;
storage: R2Bucket;
};

export type Variables = {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hono } from 'hono';
import { NotFoundError } from '@phoenix/core/errors';
import { NotFoundError } from '@cloudflarebook.com/core/errors';
import { ErrorTemplate } from './routes/_error';
import { Bindings, Variables } from './context';
import { handlebars } from './routes/handlebars';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FC } from 'hono/jsx';
import { raw } from 'hono/html';
import { Blog } from '@phoenix/core/entities';
import { Blog } from '@cloudflarebook.com/core/entities';

type Props = {
blog?: Blog,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sha256Sum } from "@phoenix/core/crypto";
import { sha256Sum } from "@cloudflarebook.com/core/crypto";
import { Context } from "../context";
import { handleCaching } from "../caching";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sha256Sum } from "@phoenix/core/crypto";
import { sha256Sum } from "@cloudflarebook.com/core/crypto";
import { Context } from "../context";
import { getBlog, getPosts } from "../utils";
import { handleCaching } from "../caching";
import { Blog, Page } from '@phoenix/core/entities';
import { Blog, Page } from '@cloudflarebook.com/core/entities';
import type { FC } from 'hono/jsx';
import { Base } from './_base';
import { date } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sha256Sum } from "@phoenix/core/crypto";
import { sha256Sum } from "@cloudflarebook.com/core/crypto";
import { Context } from "../context";
import { getBlog, getPage, maxTime } from "../utils";
import templatesHash from './templates_sha256.txt';
import { handleCaching } from "../caching";
import { Blog, Page } from "@phoenix/core/entities";
import { Blog, Page } from "@cloudflarebook.com/core/entities";
import { FC } from "hono/jsx";
import { Base } from "./_base";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiError, ApiResponse } from "@phoenix/core/api";
import { Blog, BlogValidator, Page, PageValidator } from "@phoenix/core/entities";
import { InternalServerError, NotFoundError } from "@phoenix/core/errors";
import { ApiError, ApiResponse } from "@cloudflarebook.com/core/api";
import { Blog, BlogValidator, Page, PageValidator } from "@cloudflarebook.com/core/entities";
import { InternalServerError, NotFoundError } from "@cloudflarebook.com/core/errors";
import { Context } from "./context";

export async function getBlog(ctx: Context, domain: string): Promise<Blog> {
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e0f0535

Please sign in to comment.