update,
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import '../styles/globals.css'
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />
|
||||
}
|
||||
|
||||
export default MyApp
|
@@ -0,0 +1,5 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","age":30}' http://localhost:5000/api/data
|
||||
|
||||
# curl http://localhost:5000/api/data
|
||||
# curl -F "file=@test.txt" http://localhost:3000/api/hello
|
||||
curl -X POST -F "file=@test.txt" http://localhost:3000/api/testFileupload
|
||||
|
@@ -0,0 +1 @@
|
||||
helloworld
|
@@ -0,0 +1,21 @@
|
||||
//
|
||||
import formidable from "formidable";
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: false,
|
||||
},
|
||||
};
|
||||
|
||||
export default function handler(req, res) {
|
||||
try {
|
||||
const form = new formidable.IncomingForm();
|
||||
form.parse(req, async (err, fields, files) => {
|
||||
console.log(files.zip.filepath, 222);
|
||||
const lottieJSON = await zip2json(files.zip.filepath);
|
||||
return res.status(200).json({ json: lottieJSON?.[0] });
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: JSON.stringify(error, Object.getOwnPropertyNames(error)) });
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
//
|
||||
import formidable from "formidable";
|
||||
import axios from "axios";
|
||||
import fs from "fs";
|
||||
|
||||
// export const config = {
|
||||
// api: { bodyParser: false },
|
||||
// };
|
||||
|
||||
export default async function handler(req, res) {
|
||||
try {
|
||||
// console.log(req.body);
|
||||
const response = await axios.post("http://localhost:5000/uploader", req.body);
|
||||
console.log(response);
|
||||
res.status(200).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
import Head from "next/head";
|
||||
import Image from "next/image";
|
||||
import styles from "../styles/Home.module.css";
|
||||
//
|
||||
import axios from "axios";
|
||||
|
||||
//
|
||||
export default function Home() {
|
||||
async function onSubmit(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const formData = new FormData(event.currentTarget);
|
||||
// const response = await fetch("/api/testFileupload", {
|
||||
// method: "POST",
|
||||
// body: formData,
|
||||
// });
|
||||
|
||||
const response = await fetch("http://localhost:5000/uploader", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
// Handle response if necessary
|
||||
const data = await response.json();
|
||||
// ...
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>helloworld</div>
|
||||
<form onSubmit={onSubmit}>
|
||||
<input type="text" name="name" />
|
||||
<input type="file" name="file" />
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
import Head from "next/head";
|
||||
import Image from "next/image";
|
||||
import styles from "../styles/Home.module.css";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Head>
|
||||
<title>Create Next App</title>
|
||||
<meta name="description" content="Generated by create next app" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
||||
<main className={styles.main}>
|
||||
<h1 className={styles.title}>
|
||||
Welcome to <a href="https://nextjs.org">Next.js!</a>
|
||||
</h1>
|
||||
|
||||
<p className={styles.description}>
|
||||
Get started by editing <code className={styles.code}>pages/index.js</code>
|
||||
</p>
|
||||
|
||||
<div className={styles.grid}>
|
||||
<a href="https://nextjs.org/docs" className={styles.card}>
|
||||
<h2>Documentation →</h2>
|
||||
<p>Find in-depth information about Next.js features and API.</p>
|
||||
</a>
|
||||
|
||||
<a href="https://nextjs.org/learn" className={styles.card}>
|
||||
<h2>Learn →</h2>
|
||||
<p>Learn about Next.js in an interactive course with quizzes!</p>
|
||||
</a>
|
||||
|
||||
<a href="https://github.com/vercel/next.js/tree/canary/examples" className={styles.card}>
|
||||
<h2>Examples →</h2>
|
||||
<p>Discover and deploy boilerplate example Next.js projects.</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
className={styles.card}
|
||||
>
|
||||
<h2>Deploy →</h2>
|
||||
<p>Instantly deploy your Next.js site to a public URL with Vercel.</p>
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer className={styles.footer}>
|
||||
<a
|
||||
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Powered by{" "}
|
||||
<span className={styles.logo}>
|
||||
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
|
||||
</span>
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user