kreteshq / kretes

A Programming Environment for TypeScript & Deno
https://kretes.dev/
Other
676 stars 35 forks source link

File Upload - Property 'files' does not exist on type 'Request' #49

Closed lukas-runge closed 4 years ago

lukas-runge commented 4 years ago

Hey @zaiste!

Thank you very much for your beautiful framework! It just saved me a ton of time and helped me focus on actually building the API itself. I am using my API to upload files to the server as well and ran into this error: grafik Is there a way of fixing it or should I just ignore the error? Cuz' it seems to work anyways.

Edit: Just found out you already fixed it in this commit: c944078 Tried to update / reinstall huncwot but your change is still not present in the version I am able to pull from npm (0.52.0). I have now fixed it manually, but I am curious why this change isn't present in the newest npm version of the framework.

Edit 2: When creating a Project with hc new package.json still contains Version 0.51.0. And Project install overwrites correct global install.

Edit 3: Found the reason for the issue! You missed committing the version update to /template/base/package.json (5faaeb0) before the new release commit (652f64f).

Kind regards Lukas

routes.ts 🔽

import { Routes } from 'huncwot';
import { OK } from 'huncwot/response';
import { FSWatcher } from 'chokidar';
import { promises as fs } from 'fs';
import { join } from 'path';

const routes: Routes = {
  GET: {
    // implicit `return` with a `text/plain` response
    '/hello': _ => 'Hello Huncwot',

    // explicit `return` with a 200 response of `application/json` type
    '/json': _ => {
      return OK({ a: 1, b: 2 });
    },

    // set your own headers
    '/headers': _ => {
      return { body: 'Hello B', statusCode: 201, headers: { 'Authorization': 'PASS' } };
    }
  },
  POST: {
    // request body is parsed in `params` by default
    '/bim': request => {
      return `Hello POST! ${request.params.name}`;
    },
    '/upload': async ({ files }) => {
      const { name, data } = files.foo;
      const cwd = process.cwd();

      await fs.writeFile(join(cwd, 'static', 'uploads', name), data);

      return 'Uploaded';
    }
  }
};

export default routes;
zaiste commented 4 years ago

@lukas-runge thank you! the fixes are being developed right now :)

zaiste commented 4 years ago

@lukas-runge I've just released 0.52.1 that should fix the dependency issue.

lukas-runge commented 4 years ago

@zaiste It does. 👍 Thank you very much! Keep up the great work - love your stuff! 😉😎💪

Kind regards Lukas