silverwolf-x's picture
download
raw
879 Bytes
import Cors from 'cors'
// Helper method to wait for a middleware to execute before continuing
// And to throw an error when an error happens in a middleware
function initMiddleware(middleware) {
return (req, res) =>
new Promise((resolve, reject) => {
middleware(req, res, (result) => {
if (result instanceof Error) {
return reject(result)
}
return resolve(result)
})
})
}
// Initialize the cors middleware
const cors = initMiddleware(
// You can read more about the available options here: https://github.com/expressjs/cors#configuration-options
Cors({
// Only allow requests with GET, POST and OPTIONS
methods: ['GET', 'POST', 'OPTIONS'],
})
)
export default async function handler(req, res) {
// Run cors
await cors(req, res)
// Rest of the API logic
res.json({ message: 'Hello Everyone!' })
}

Xet Storage Details

Size:
879 Bytes
·
Xet hash:
79089b842cbbaeabff75fa15e5ade41c555b5c8a613350084311632b7d944b42

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.