Skip to content

Commit

Permalink
rename blog portal to admin portal
Browse files Browse the repository at this point in the history
  • Loading branch information
adidoesnt committed Nov 25, 2024
1 parent e348712 commit 9fe15ad
Show file tree
Hide file tree
Showing 79 changed files with 111 additions and 115 deletions.
23 changes: 9 additions & 14 deletions .github/workflows/deploy-blog.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
name: Deploy Blog
name: Deploy All Services

on:
workflow_dispatch: {}
push:
branches:
- main
paths:
- 'apps/backend/blog/**'
- 'apps/frontend/blog-portal/**'
- 'infra/**'
- 'packages/**'

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down Expand Up @@ -49,9 +44,9 @@ jobs:
--auto-approve
working-directory: infra

build-and-push-backend:
build-and-push-blog-service:
needs: setup-core-infra
name: Build and push backend
name: Build and push backend blog service
runs-on: ubuntu-latest

steps:
Expand All @@ -77,9 +72,9 @@ jobs:
run: |
docker push ${{ steps.login-ecr.outputs.registry }}/blog-repo:latest
build-and-push-frontend:
build-and-push-admin-portal:
needs: setup-core-infra
name: Build and push frontend
name: Build and push frontend admin portal
runs-on: ubuntu-latest

steps:
Expand All @@ -99,15 +94,15 @@ jobs:
run: |
bun install
bun run build
working-directory: apps/frontend/blog-portal
working-directory: apps/frontend/admin-portal

- name: Push to S3
run: |
aws s3 sync ./dist/ s3://blog-portal-deployment-bucket/
working-directory: apps/frontend/blog-portal
aws s3 sync ./dist/ s3://admin-portal-deployment-bucket/
working-directory: apps/frontend/admin-portal

setup-additional-infra:
needs: [build-and-push-backend, build-and-push-frontend]
needs: [build-and-push-blog-service, build-and-push-admin-portal]
name: Run Terraform for additional infrastructure
runs-on: ubuntu-latest

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/blog/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ URL_EXPIRY_IN_SECONDS=
# Website (Frontend, Production only)
WEBSITE_URL=

# Blog Portal (Frontend, Production only)
BLOG_PORTAL_URL=
# Admin Portal (Frontend, Production only)
ADMIN_PORTAL_URL=

# Blog (Backend,Production only)
BLOG_URL=
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/blog/src/plugins/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { logger } from "src/utils";
const {
NODE_ENV = "PROD",
WEBSITE_URL = "DUMMY-URL",
BLOG_PORTAL_URL = "DUMMY-URL",
ADMIN_PORTAL_URL = "DUMMY-URL",
BLOG_URL = "DUMMY-URL",
} = process.env;

const originConfig =
NODE_ENV === "DEV" ? undefined : [WEBSITE_URL, BLOG_PORTAL_URL, BLOG_URL];
NODE_ENV === "DEV" ? undefined : [WEBSITE_URL, ADMIN_PORTAL_URL, BLOG_URL];

export const corsPlugin = () => {
const config = {
Expand Down
16 changes: 8 additions & 8 deletions apps/backend/blog/src/plugins/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Elysia } from "elysia";
import { CreatePostBodyType, GetPostQueryType, UpdatePostBodyType } from "../model";
import { postService } from "../service";
import { authPlugin, AuthPluginProps } from "./auth";
import { BlogPortalPostError, BlogPortalPostErrorMessage } from "@/packages/types/error";
import { AdminPortalPostError, AdminPortalPostErrorMessage } from "@/packages/types/error";
import { Status } from "@/packages/types/response";
import { logger } from "src/utils";

Expand Down Expand Up @@ -44,13 +44,13 @@ export const postPlugin = () => {
.get("/:postId", async ({ params, set }) => {
try {
const post = await postService.findById(params.postId);
if (!post) throw new BlogPortalPostError(BlogPortalPostErrorMessage.POST_NOT_FOUND, Status.NOT_FOUND);
if (!post) throw new AdminPortalPostError(AdminPortalPostErrorMessage.POST_NOT_FOUND, Status.NOT_FOUND);

set.status = Status.OK;

return post.toJSON();
} catch (e) {
const error = e as BlogPortalPostError;
const error = e as AdminPortalPostError;
set.status = error.status ?? Status.INTERNAL_SERVER_ERROR;

const errMessage = "💀 Failed to get post:";
Expand All @@ -62,7 +62,7 @@ export const postPlugin = () => {
.put("/:postId", async ({ params, body, set }) => {
try {
const post = await postService.updatePost(params.postId, body);
if (!post) throw new BlogPortalPostError(BlogPortalPostErrorMessage.UPDATE_FAILED, Status.INTERNAL_SERVER_ERROR);
if (!post) throw new AdminPortalPostError(AdminPortalPostErrorMessage.UPDATE_FAILED, Status.INTERNAL_SERVER_ERROR);

set.status = Status.OK;

Expand All @@ -81,15 +81,15 @@ export const postPlugin = () => {
.delete("/:postId", async ({ params, set }) => {
try {
const post = await postService.findById(params.postId);
if (!post) throw new BlogPortalPostError(BlogPortalPostErrorMessage.POST_NOT_FOUND, Status.NOT_FOUND);
if (!post) throw new AdminPortalPostError(AdminPortalPostErrorMessage.POST_NOT_FOUND, Status.NOT_FOUND);

await postService.deletePost(post._id);

set.status = Status.OK;

return "Post deleted";
} catch (e) {
const error = e as BlogPortalPostError;
const error = e as AdminPortalPostError;
set.status = error.status ?? Status.INTERNAL_SERVER_ERROR;

const errMessage = "💀 Failed to delete post:";
Expand All @@ -103,13 +103,13 @@ export const postPlugin = () => {
async ({ body, set }) => {
try {
const post = await postService.createPost(body);
if (!post) throw new BlogPortalPostError(BlogPortalPostErrorMessage.CREATE_FAILED, Status.INTERNAL_SERVER_ERROR);
if (!post) throw new AdminPortalPostError(AdminPortalPostErrorMessage.CREATE_FAILED, Status.INTERNAL_SERVER_ERROR);

set.status = Status.CREATED;

return post.toJSON();
} catch (e) {
const error = e as BlogPortalPostError;
const error = e as AdminPortalPostError;
set.status = error.status ?? Status.INTERNAL_SERVER_ERROR;

const errMessage = "💀 Failed to create post:";
Expand Down
14 changes: 7 additions & 7 deletions apps/backend/blog/src/plugins/user.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Elysia, t } from "elysia";
import { tokenService, userService } from "../service";
import {
BlogPortalAuthError,
BlogPortalAuthErrorMessage,
AdminPortalAuthError,
AdminPortalAuthErrorMessage,
} from "@/packages/types/error";
import { Status } from "@/packages/types/response";
import { logger } from "src/utils";
Expand All @@ -28,17 +28,17 @@ export const userPlugin = () => {
);

if (!user) {
throw new BlogPortalAuthError(
throw new AdminPortalAuthError(
errMessage ??
BlogPortalAuthErrorMessage.USER_NOT_FOUND,
AdminPortalAuthErrorMessage.USER_NOT_FOUND,
Status.NOT_FOUND
);
}

if (!token) {
throw new BlogPortalAuthError(
throw new AdminPortalAuthError(
errMessage ??
BlogPortalAuthErrorMessage.INCORRECT_PASSWORD,
AdminPortalAuthErrorMessage.INCORRECT_PASSWORD,
Status.FORBIDDEN
);
}
Expand All @@ -57,7 +57,7 @@ export const userPlugin = () => {
maxAge,
};
} catch (e) {
const error = e as BlogPortalAuthError;
const error = e as AdminPortalAuthError;
set.status = error.status ?? Status.INTERNAL_SERVER_ERROR;
return error.message;
}
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/blog/src/service/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import bcrypt from "bcryptjs";
import { userRepository } from "../repository";
import { generateToken, getUserFromToken } from "../utils/jwt";
import { logger } from "src/utils";
import { BlogPortalAuthError, BlogPortalAuthErrorMessage } from "@/packages/types/error";
import { AdminPortalAuthError, AdminPortalAuthErrorMessage } from "@/packages/types/error";
import { Status } from "@/packages/types/response";

export const findByUsername = async (username: string) => {
Expand Down Expand Up @@ -36,7 +36,7 @@ export const login = async (username: string, password: string) => {
return {
user: null,
token: null,
errMessage: BlogPortalAuthErrorMessage.USER_NOT_FOUND,
errMessage: AdminPortalAuthErrorMessage.USER_NOT_FOUND,
};
}

Expand All @@ -47,7 +47,7 @@ export const login = async (username: string, password: string) => {
return {
user,
token: null,
errMessage: BlogPortalAuthErrorMessage.INCORRECT_PASSWORD,
errMessage: AdminPortalAuthErrorMessage.INCORRECT_PASSWORD,
};
}

Expand All @@ -70,8 +70,8 @@ export const refreshToken = async (token: string) => {
const userFromDb = await findByUsername(username);

if (!userFromDb) {
throw new BlogPortalAuthError(
BlogPortalAuthErrorMessage.USER_NOT_FOUND,
throw new AdminPortalAuthError(
AdminPortalAuthErrorMessage.USER_NOT_FOUND,
Status.NOT_FOUND
);
}
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions apps/frontend/admin-portal/build-and-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

bun run build

aws s3 sync ./dist/ s3://admin-portal-deployment-bucket/
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="/Logo.png" />
<link rel="stylesheet" href="/index.css" />
<title>Beings of Habit - Blog Portal</title>
<title>Beings of Habit - Admin Portal</title>
</head>

<body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "blog-portal",
"name": "admin-portal",
"version": "0.0.0",
"private": true,
"type": "module",
Expand Down
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const LoginCard = ({ children, imgSrc }: Readonly<LoginCardProps>) => {
<div className="flex flex-col gap-2">
<CardTitle className="text-xl font-bold">Log In</CardTitle>
<CardDescription>
Please enter you credentials below to enter the Beings of Habit blog
Please enter you credentials below to enter the Beings of Habit admin
portal.
</CardDescription>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import { apiClient } from "@/utils";
import { useAuth } from "@/context/auth";
import { useNavigate, useSearch } from "@tanstack/react-router";
import {
BlogPortalAuthError,
BlogPortalAuthErrorMessage,
AdminPortalAuthErrorMessage,
} from "@/packages/types/error";
import { BlogPortalAuthErrorResponse } from "@/packages/types/response";
import { AdminPortalAuthErrorResponse } from "@/packages/types/response";

const { VITE_FRONTEND_URL = "DUMMY-URL" } = import.meta.env;

Expand Down Expand Up @@ -57,17 +56,17 @@ export const LoginForm = () => {
}, [search, navigate]);

const handleError = useCallback(
({ response }: BlogPortalAuthErrorResponse) => {
({ response }: AdminPortalAuthErrorResponse) => {
switch (response.data) {
case BlogPortalAuthErrorMessage.USER_NOT_FOUND:
case AdminPortalAuthErrorMessage.USER_NOT_FOUND:
form.setError("username", {
message: BlogPortalAuthErrorMessage.USER_NOT_FOUND,
message: AdminPortalAuthErrorMessage.USER_NOT_FOUND,
type: "value",
});
break;
case BlogPortalAuthErrorMessage.INCORRECT_PASSWORD:
case AdminPortalAuthErrorMessage.INCORRECT_PASSWORD:
form.setError("password", {
message: BlogPortalAuthErrorMessage.INCORRECT_PASSWORD,
message: AdminPortalAuthErrorMessage.INCORRECT_PASSWORD,
type: "value",
});
break;
Expand All @@ -92,7 +91,7 @@ export const LoginForm = () => {
setSessionExpiryWithMaxAge(user.maxAge);
setUser(user);
} catch (e) {
const error = e as BlogPortalAuthErrorResponse;
const error = e as AdminPortalAuthErrorResponse;
handleError(error);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useAuth } from "@/context/auth";
import { useNavigate } from "@tanstack/react-router";
import { queryClient } from "@/routes/__root";

const DEFAULT_HEADER_IMAGE_URL = "https://picsum.photos/300/200";

const getDefaultReleaseDate = () => {
const now = new Date();
now.setDate(now.getDate() + 1);
Expand All @@ -19,7 +21,7 @@ const defaultPost: Omit<Post, "_id" | "author"> = {
blurb: "This is my new post.",
content: "This is my new post.",
category: Category.MISC,
headerImageURL: "https://picsum.photos/300/200",
headerImageURL: DEFAULT_HEADER_IMAGE_URL,
releaseDate: getDefaultReleaseDate(),
};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions apps/frontend/blog-portal/build-and-push.sh

This file was deleted.

18 changes: 9 additions & 9 deletions infra/cloudfront.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
variable "blog_portal_certificate_arn" {
variable "admin_portal_certificate_arn" {
type = string
default = "arn:aws:acm:us-east-1:839459181456:certificate/2aced4de-0e15-4781-8e3f-8dbd111d496b"
}

variable "blog_portal_alias" {
variable "admin_portal_alias" {
type = string
default = "admin.boh-services.com"
}

resource "aws_cloudfront_distribution" "blog_portal_distribution" {
resource "aws_cloudfront_distribution" "admin_portal_distribution" {
origin {
custom_origin_config {
origin_protocol_policy = "http-only"
http_port = 80
https_port = 443
origin_ssl_protocols = ["TLSv1.2", "TLSv1.1", "TLSv1"]
}
domain_name = "${aws_s3_bucket.blog_portal_bucket.bucket}.s3-website-ap-southeast-1.amazonaws.com"
origin_id = "S3-${aws_s3_bucket.blog_portal_bucket.bucket}"
domain_name = "${aws_s3_bucket.admin_portal_bucket.bucket}.s3-website-ap-southeast-1.amazonaws.com"
origin_id = "S3-${aws_s3_bucket.admin_portal_bucket.bucket}"
}

aliases = [ var.blog_portal_alias ]
aliases = [ var.admin_portal_alias ]

viewer_certificate {
acm_certificate_arn = var.blog_portal_certificate_arn
acm_certificate_arn = var.admin_portal_certificate_arn
ssl_support_method = "sni-only"
}

Expand All @@ -33,7 +33,7 @@ resource "aws_cloudfront_distribution" "blog_portal_distribution" {
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "S3-${aws_s3_bucket.blog_portal_bucket.bucket}"
target_origin_id = "S3-${aws_s3_bucket.admin_portal_bucket.bucket}"
viewer_protocol_policy = "redirect-to-https"
compress = true

Expand All @@ -52,5 +52,5 @@ resource "aws_cloudfront_distribution" "blog_portal_distribution" {
}
}

depends_on = [ aws_s3_bucket.blog_portal_bucket ]
depends_on = [ aws_s3_bucket.admin_portal_bucket ]
}
4 changes: 2 additions & 2 deletions infra/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ resource "aws_ecs_task_definition" "blog_task_definition" {
"name" : "WEBSITE_URL",
"value" : var.main_website_url
}, {
"name" : "BLOG_PORTAL_URL",
"value" : var.blog_portal_url
"name" : "ADMIN_PORTAL_URL",
"value" : var.admin_portal_url
}, {
"name" : "BLOG_URL",
"value" : var.blog_service_url
Expand Down
Loading

0 comments on commit 9fe15ad

Please sign in to comment.