From 56d673a9ec8f3fafe1db270f47df3e1cca6c5702 Mon Sep 17 00:00:00 2001 From: Lumither Tao Date: Wed, 5 Jun 2024 01:57:18 +0800 Subject: [PATCH] feat(global) new api rule, NextImage support, test openresty --- app/blog/BlogPostCard.tsx | 9 ++++++--- app/blog/fetch_posts_list.ts | 2 +- app/blog/post/[id]/generate.tsx | 6 ++---- backend/src/main.rs | 6 +++--- components/Navbar.tsx | 3 +++ next.config.mjs | 11 ++++++++++- openresty/conf/blog_backend.conf | 16 ++++++++++++++++ openresty/deploy.sh | 4 ++++ package.json | 3 ++- 9 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 openresty/conf/blog_backend.conf create mode 100755 openresty/deploy.sh diff --git a/app/blog/BlogPostCard.tsx b/app/blog/BlogPostCard.tsx index b1e6f11..814ab60 100644 --- a/app/blog/BlogPostCard.tsx +++ b/app/blog/BlogPostCard.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Card, CardBody, CardFooter } from '@nextui-org/card'; import { Chip, Image } from '@nextui-org/react'; +import NextImage from 'next/image'; import Link from 'next/link'; import { MdCalendarMonth, MdNorthEast } from 'react-icons/md'; @@ -28,16 +29,18 @@ function BlogPostCard({ post }: Props) { isHoverable > - { header_img !== '' &&
+ + { header_img !== '' &&
{
} diff --git a/app/blog/fetch_posts_list.ts b/app/blog/fetch_posts_list.ts index aebb739..6e9303f 100644 --- a/app/blog/fetch_posts_list.ts +++ b/app/blog/fetch_posts_list.ts @@ -1,7 +1,7 @@ import axios from 'axios'; export default async function fetch_posts_list(): Promise { - const response = await axios(`http://localhost:${ process.env.BACKEND_PORT }/api/get/post_list`); + const response = await axios(`${ process.env.BACKEND_URL }/get_post_list`); if (response.status !== 200) { throw new Error(response.statusText); } diff --git a/app/blog/post/[id]/generate.tsx b/app/blog/post/[id]/generate.tsx index 3771f64..72053c3 100644 --- a/app/blog/post/[id]/generate.tsx +++ b/app/blog/post/[id]/generate.tsx @@ -1,5 +1,3 @@ -'use server'; - import React from 'react'; import Markdown from 'react-markdown'; import { Card, CardBody } from '@nextui-org/card'; @@ -19,7 +17,7 @@ async function Generate(props: Props) { let response: any; try { - response = await axios(`http://localhost:${ process.env.BACKEND_PORT }/api/get/post/${ props.id }`); + response = await axios(`${ process.env.BACKEND_URL }/get_post/${ props.id }`); } catch (e) { return ( @@ -38,7 +36,7 @@ async function Generate(props: Props) { { (post_data as any)['content'] } diff --git a/backend/src/main.rs b/backend/src/main.rs index d92c900..7f97b02 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -32,9 +32,9 @@ async fn main() -> Result<(), Box> { .expect("failed to load database"); let app = Router::new() - .route("/api/post/refresh", post(refresh)) - .route("/api/get/post_list", get(get_post_list)) - .route("/api/get/post/:post_id", get(get_post)) + .route("/refresh_posts", post(refresh)) + .route("/get_post_list", get(get_post_list)) + .route("/get_post/:post_id", get(get_post)) .with_state(db_pool); let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", port)).await?; diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 827abdb..b16b09b 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react'; import { Button, Image } from '@nextui-org/react'; +import NextImage from 'next/image'; import { IoFileTrayFull, IoHome, @@ -115,11 +116,13 @@ function Navbar() {
{
diff --git a/next.config.mjs b/next.config.mjs index 4678774..2216b31 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,13 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + images: { + remotePatterns: [ + { + protocol: 'https', + hostname: 'oss.lumither.com' + } + ] + } +}; export default nextConfig; diff --git a/openresty/conf/blog_backend.conf b/openresty/conf/blog_backend.conf new file mode 100644 index 0000000..4d297fd --- /dev/null +++ b/openresty/conf/blog_backend.conf @@ -0,0 +1,16 @@ + +location / { + default_type text/html; + proxy_pass http://localhost:3000; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +} + +location /api/ { + rewrite ^/api(/.*)$ $1 break; + proxy_pass http://localhost:3001; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; +} diff --git a/openresty/deploy.sh b/openresty/deploy.sh new file mode 100755 index 0000000..dc0a79c --- /dev/null +++ b/openresty/deploy.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rm -rf /opt/openresty/nginx/lua +cp -r ./lua /opt/openresty/nginx diff --git a/package.json b/package.json index 8d6e19b..5f5fc21 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "rehype-sanitize": "^6.0.0", "remark-frontmatter": "^5.0.0", "remark-gfm": "^4.0.0", - "remark-toc": "^9.0.0" + "remark-toc": "^9.0.0", + "sharp": "^0.33.4" }, "devDependencies": { "@tailwindcss/typography": "^0.5.13",