mirror of
https://github.com/versia-pub/blog.git
synced 2026-03-13 01:29:15 +01:00
feat: ✨ Initialize new repo
This commit is contained in:
commit
e7941231a5
23 changed files with 858 additions and 0 deletions
24
server/api/article.get.ts
Normal file
24
server/api/article.get.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { join } from "node:path";
|
||||
import { getPost } from "~/composables/server/Post";
|
||||
import { createError, defineEventHandler } from "#imports";
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const url = new URL(
|
||||
event.node.req.url ?? "",
|
||||
`http://${event.node.req.headers.host}`,
|
||||
);
|
||||
|
||||
// Get the path query parameter
|
||||
const filePath = decodeURIComponent(url.searchParams.get("path") ?? "");
|
||||
|
||||
const post = getPost(filePath);
|
||||
|
||||
if (!post) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
message: "Post not found",
|
||||
});
|
||||
}
|
||||
|
||||
return post;
|
||||
});
|
||||
8
server/api/articles.get.ts
Normal file
8
server/api/articles.get.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { getPostList } from "~/composables/server/Post";
|
||||
import { defineEventHandler } from "#imports";
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const files = await getPostList();
|
||||
|
||||
return files ?? [];
|
||||
});
|
||||
3
server/tsconfig.json
Normal file
3
server/tsconfig.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"extends": "../.nuxt/tsconfig.server.json"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue