Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import nextMDX from '@next/mdx'
import remarkGfm from 'remark-gfm'
import rehypePrism from '@mapbox/rehype-prism'
import nextMDX from '@next/mdx';
import remarkGfm from 'remark-gfm';
import rehypePrism from '@mapbox/rehype-prism';

/** @type {import('next').NextConfig} */
const nextConfig = {
pageExtensions: ['jsx', 'mdx'],
pageExtensions: ['jsx', 'mdx', 'js'],
reactStrictMode: true,
experimental: {
scrollRestoration: true,
// scrollRestoration: true, // Comment out or remove this line
},
}
};

const withMDX = nextMDX({
extension: /\.mdx?$/,
options: {
remarkPlugins: [remarkGfm],
rehypePlugins: [rehypePrism],
},
})
});

export default withMDX(nextConfig)
export default withMDX(nextConfig);
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@next/mdx": "^13.0.2",
"@tailwindcss/typography": "^0.5.4",
"autoprefixer": "^10.4.12",
"axios": "^1.2.0",
"axios": "^1.7.2",
"clsx": "^2.0.0",
"fast-glob": "^3.2.11",
"feed": "^4.2.2",
Expand Down
18 changes: 8 additions & 10 deletions src/api/axiosConfig.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import axios from "axios"
import { isHyperlink } from '@/lib/isHyperlink'
import axios from 'axios';

const BASE_URL = process.env.DOTNET_SERVER_URL
const axiosInstance = axios.create({
baseURL: 'http://localhost:5000/api',
headers: {
'Content-Type': 'application/json',
},
});

const AXIOS_BASE = axios.create({
baseURL: BASE_URL,
})

const JSON_CLIENT = isHyperlink(BASE_URL) ? AXIOS_BASE : false

export default JSON_CLIENT
export default axiosInstance;
60 changes: 44 additions & 16 deletions src/api/postsApi.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
import API from './axiosConfig'
// src/api/postsApi.js

export const getPosts = () => {
const apiUrl = process.env.DOTNET_SERVER_URL || 'http://localhost:5000';

export const getPosts = async () => {
try {
return API.get('/posts/')
.then((res) => res.data)
}
catch (e) {
console.error(e)
return []
const response = await fetch(`${apiUrl}/api/posts`);
if (!response.ok) {
const errorDetails = await response.text();
throw new Error(`Error fetching posts: ${response.status} ${response.statusText} - ${errorDetails}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching posts:', error);
throw error;
}
}
};

export const getPost = (postSlug) => {
export const getPost = async (slug) => {
try {
return API.get(`/posts/${postSlug}`)
.then((res) => res.data)
const response = await fetch(`${apiUrl}/api/posts/${slug}`);
if (!response.ok) {
const errorDetails = await response.text();
throw new Error(`Error fetching post: ${response.status} ${response.statusText} - ${errorDetails}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching post:', error);
throw error;
}
catch (e) {
console.error(e)
return {}
};

export const createPost = async (post) => {
try {
const response = await fetch(`${apiUrl}/api/posts`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(post),
});
if (!response.ok) {
const errorDetails = await response.text();
throw new Error(`Error creating post: ${response.status} ${response.statusText} - ${errorDetails}`);
}
return await response.json();
} catch (error) {
console.error('Error creating post:', error);
throw error;
}
}
};
57 changes: 57 additions & 0 deletions src/components/CreatePostForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useState } from 'react';
import { createPost } from '../api/postsApi';

const CreatePostForm = () => {
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [body, setBody] = useState('');

const handleSubmit = async (e) => {
e.preventDefault();
try {
const newPost = { title, description, body };
const response = await createPost(newPost);
console.log('Post created successfully:', response);
// Optionally, reset the form or handle post-creation logic
setTitle('');
setDescription('');
setBody('');
} catch (error) {
console.error('Error creating post:', error);
}
};

return (
<form onSubmit={handleSubmit}>
<div>
<label>Title:</label>
<input
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
</div>
<div>
<label>Description:</label>
<input
type="text"
value={description}
onChange={(e) => setDescription(e.target.value)}
required
/>
</div>
<div>
<label>Body:</label>
<textarea
value={body}
onChange={(e) => setBody(e.target.value)}
required
/>
</div>
<button type="submit">Create Post</button>
</form>
);
};

export default CreatePostForm;
Loading