This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$primary-500: #e91e63; | |
$primary-600: #d81b60; | |
$primary-700: #c2185b; | |
// Import Pico | |
@import "@picocss/pico/scss/pico"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install @picocss/pico --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define variables to override default ones | |
$primary-color: #2e5bec; | |
$dark-color: #3e396b; | |
// Import full Spectre source code | |
@import "node_modules/spectre.css/src/spectre"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install spectre.css --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("dotenv").config(); | |
import { createServer } from "http"; | |
import next from "next"; | |
import express from "express"; | |
import { method2 } from "./lib/upload"; | |
const port = parseInt(process.env.PORT || "3000", 10); | |
const dev = process.env.NODE_ENV !== "production"; | |
const nextApp = next({ dev }); | |
const handle = nextApp.getRequestHandler(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
import { PassThrough } from "stream"; | |
const uploadStream = (file: formidable.File) => { | |
const pass = new PassThrough(); | |
const stream = gcs.createWriteStream( | |
file.originalFilename ?? file.newFilename, | |
file.mimetype ?? undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const method2 = ( | |
req: NextApiRequest | IncomingMessage, | |
res: NextApiResponse | Response | |
) => { | |
// @ts-ignore | |
const form = formidable({ fileWriteStreamHandler: uploadStream }); | |
form.parse(req, () => { | |
res.status(200).json("File upload complete"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import formidable from "./formidable-serverless"; | |
import { createReadStream } from "fs"; | |
import { IncomingMessage } from "http"; | |
import { NextApiRequest, NextApiResponse } from "next"; | |
import parseForm from "./parseForm"; | |
import * as gcs from "./gcs"; | |
import { Response } from "express"; | |
export const method1 = async ( | |
req: NextApiRequest | IncomingMessage, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { NextApiRequest, NextApiResponse } from "next"; | |
import { method1 } from "../../lib/upload"; | |
export default async function handler( | |
req: NextApiRequest, | |
res: NextApiResponse | |
) { | |
if (req.method !== "POST") { | |
res.status(400).send(`Invalid method: ${req.method}`); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import formidable from "./formidable-serverless"; | |
import IncomingForm from "formidable/Formidable"; | |
import { IncomingMessage } from "http"; | |
const parseForm = async ( | |
form: IncomingForm, | |
req: IncomingMessage | |
): Promise<{ fields: formidable.Fields; files: formidable.Files }> => { | |
return await new Promise(async (resolve, reject) => { | |
form.parse(req, function (err, fields, files) { |