Skip to content

Commit

Permalink
Merge pull request #510 from mfts/feat/bulk
Browse files Browse the repository at this point in the history
fix: set headers
  • Loading branch information
mfts authored Jul 12, 2024
2 parents d88837c + 9fc3945 commit 98fe29b
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions pages/api/file/tus/[[...file]].ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import type { NextApiRequest, NextApiResponse } from "next";

import { client } from "@/trigger";
import { DocumentStorageType } from "@prisma/client";
import slugify from "@sindresorhus/slugify";
import { S3Store } from "@tus/s3-store";
import { Server, Upload } from "@tus/server";
import { Server } from "@tus/server";
import { getServerSession } from "next-auth/next";
import { IncomingMessage } from "node:http";
import path from "node:path";

import { newId } from "@/lib/id-helper";
import prisma from "@/lib/prisma";

import { authOptions } from "../../auth/[...nextauth]";

Expand Down Expand Up @@ -58,6 +54,26 @@ const tusServer = new Server({
});

export default function handler(req: NextApiRequest, res: NextApiResponse) {
// Set CORS headers for all responses
res.setHeader(
"Access-Control-Allow-Methods",
"GET,POST,PUT,HEAD,DELETE,OPTIONS",
);
res.setHeader(
"Access-Control-Allow-Headers",
"Content-Type,Upload-Length,Upload-Offset,Upload-Metadata,Upload-Defer-Length,Upload-Concat",
);
res.setHeader(
"Access-Control-Expose-Headers",
"Upload-Offset,Upload-Length,Location",
);

if (req.method === "OPTIONS") {
// Handle preflight requests
res.status(204).end();
return;
}

// Get the session
const session = getServerSession(req, res, authOptions);
if (!session) {
Expand Down

0 comments on commit 98fe29b

Please sign in to comment.