emptygif
ภาษา: ไทย

ภาษาและเฟรมเวิร์กทั้งหมด

AdonisJS TypeScript

ตัวอย่างโค้ด TypeScript สำหรับ AdonisJS ที่ตอบคำขอไปยัง /pixel.gif ด้วย GIF ว่าง ซึ่งถอดรหัสเพียงครั้งเดียวตอนเริ่มทำงาน

AdonisJS TypeScript

ติดตั้ง
npm init adonisjs@latest
ไฟล์
routes.ts
รัน
node ace serve --hmr
// start/routes.ts
import router from '@adonisjs/core/services/router';

const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

router.get('/pixel.gif', ({ response }) => {
  response.header('Content-Type', 'image/gif');
  response.header('Cache-Control', 'no-store');
  return response.send(GIF);
});

เรารันตัวอย่างโค้ดนี้และเทียบไบต์ที่ได้กลับมาแล้ว

ตรวจสอบ

curl -sI http://localhost:8080/pixel.gif

เว็บไซต์ทางการ: AdonisJS

เพิ่มเติมใน TypeScript