next runtime
v2.4.2

您需要在getServerSideProps中處理POST請求和文件上傳。
所有文檔和指南都可以在Next-runtime.meijer.ws上找到。
下一個跑步旨在將更多的邏輯移至下一個服務器的“運行時部分”,而靜態站點的生成較少。使用適當的緩存標頭,每個服務器都是(增量)靜態站點生成器。
為此,我們為您提供方便的API:
getServerSideProps中的發布請求。getServerSideProps中的文件上傳。getServerSideProps作為零config json api。 如果您不是人的文檔類型,則是一個可以讓您啟動並運行的快速示例。如果這會給您帶來疑問,請諮詢文檔。
import fs from 'fs' ;
import { handle , json } from 'next-runtime' ;
export const getServerSideProps = handle ( {
async upload ( { file , stream } ) {
stream . pipe ( fs . createWriteStream ( `/uploads/ ${ file . name } ` ) ) ;
} ,
async get ( { params , query } ) {
return json ( { name : 'Stephan Meijer' } ) ;
} ,
async post ( { req : { body } } ) {
return json ( { message : 'Thanks for your submission!' } ) ;
} ,
} ) ;
export default function Home ( { name , message } ) {
if ( message ) {
return < p > { message } </ p > ;
}
return (
< form method = "post" encType = "multipart/form-data" >
< input name = "name" defaultValue = { name } />
< input type = "file" name = "file" />
< button type = "submit" > submit </ button >
</ form >
) ;
} 您或您的雇主,滿意的用戶還是我的任何其他項目。然後,請考慮贊助我的工作,以便我可以花更多的時間來維護此類項目。
請檢查貢獻。它包含有關此存儲庫結構的信息,以幫助您啟動和運行。
謝謝這些好人(表情符號鑰匙):
斯蒂芬·梅傑(Stephan Meijer) ? ? ? | 加爾·施萊辛格(Gal Schlezinger) | 達里烏斯 | 烏瑪·艾哈邁德(Umar Ahmed) | hikaru kobori | Koichi Kiyokawa | Gorka剖宮產 |
Pandiyan Murugan |
該項目遵循全企業規範。歡迎任何形式的貢獻!