feat(global) new api rule, NextImage support, test openresty

This commit is contained in:
lumither committed 2024-06-05 01:57:18 +08:00
1 parent ffb20b64f3
commit 56d673a9ec
9 files changed
+47 -13

No files matched your search

+6 -3
View File
@@ -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 !== '' && <div className={ `w-full overflow-visible` }>
{ header_img !== '' && <div className={ `w-full overflow h-80 relative` }>
<Image
as={ NextImage }
alt={ 'cover picture' }
src={ header_img }
className={ `z-20 h-80 w-full object-cover rounded-b-none` }
className={ `w-full object-cover rounded-b-none` }
style={ {
'maskImage': 'linear-gradient(black 95%, transparent)',
'backdropFilter': 'blur(20px)'
} }
width={ `100%` }
fill
removeWrapper
></Image>
</div> }
+1 -1
View File
@@ -1,7 +1,7 @@
import axios from 'axios';
export default async function fetch_posts_list(): Promise<any> {
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);
}
+2 -4
View File
@@ -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 (
<Card className={ `w-full` }>
@@ -38,7 +36,7 @@ async function Generate(props: Props) {
<Card className={ `w-full max-w-full relative` }>
<CardBody>
<Markdown
className={ `p-5 max-w-full text-justify text-pretty会 prose prose-sm dark:prose-invert md:prose-md lg:prose-lg` }
className={ `p-5 max-w-full text-justify text-pretty prose prose-sm dark:prose-invert md:prose-md lg:prose-lg` }
remarkPlugins={ [ remarkGfm, remarkToc, remarkFrontmatter ] }
rehypePlugins={ [ rehypeHighlight, rehypeRaw, rehypeSanitize ] }
>{ (post_data as any)['content'] }</Markdown>
+3 -3
View File
@@ -32,9 +32,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
.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?;
+3
View File
@@ -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() {
<div className={ `hidden md:block` }>
<div className={ `flex justify-center items-center my-7` }>
<Image
as={ NextImage }
src={ 'https://oss.lumither.com/blog/pictures/compr/1717153492846703409_avatar.webp' }
alt={ 'avatar' }
width={ 200 }
height={ 200 }
className={ 'rounded-full justify-self-center' }
fetchPriority={ 'high' }
removeWrapper
></Image>
</div>
+10 -1
View File
@@ -1,4 +1,13 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'oss.lumither.com'
}
]
}
};
export default nextConfig;
+16
View File
@@ -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;
}
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
rm -rf /opt/openresty/nginx/lua
cp -r ./lua /opt/openresty/nginx
+2 -1
View File
@@ -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",