deligenius / multiparser

multipart/form-data parser for Deno servers
28 stars 7 forks source link

how to use with oak? #11

Closed ralyodio closed 2 years ago

ralyodio commented 3 years ago
import { multiParser } from 'https://deno.land/x/multiparser/mod.ts'
import Subscriptions from '../models/subscriptions.ts';

class Controller {
  async post(context: any) {
    const body = await multiParser(context.request.serverRequest);
    // const existing = await Subscriptions.where('email', body.email).get()
    const existing = [];

    console.log(body);

    if (existing.length) {
      return (context.response.body = "Email already exists");
    }

    const subscription = {};
    // const subscription = await Subscriptions.create({
    //   id: crypto.randomUUID(),
    //   email: body.email,
    // });

    context.response.body = subscription;
  }
}

export default new Controller();

I get error: [uncaught oak error]: TypeError - Cannot read property 'headers' of undefined

gjuoun commented 2 years ago

Sorry I've removed the oak support, unless the original Request is accessible from Oak

gjuoun commented 2 years ago

see updated oak usage in https://github.com/deligenius/multiparser#with-oak