const Koa = require("koa");
const app = new Koa();
/* const path = require('path');
const fs = require('fs');
// x-response-time
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
console.log(1, path);
});
// logger
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}`);
console.log(2, path);
});
// response
app.use(async ctx => {
ctx.body = 'hello world!';
}); */
const router = require("koa-router")();
const request = require("request");
router.get("/", async function (ctx, next) {
await new Promise(function (resolve, reject) {
var req = request(
{
method: "GET",
koa2获取图片并返回,设置静态文件目录,访问本地文件
最新推荐文章于 2024-09-24 17:12:28 发布
本文介绍了如何在Koa2应用程序中配置静态文件目录,以便能够访问和返回本地的图片资源。通过设置静态路由,可以实现用户请求图片时服务器正确响应。
摘要由CSDN通过智能技术生成