美文网首页
nodejs+koa2构建自己的图库

nodejs+koa2构建自己的图库

作者: 前端架构师陈龙威 | 来源:发表于2020-03-23 11:35 被阅读0次

    参考资料:https://juejin.im/post/5e74cd78e51d4527196d785f

    预案:前端布局:瀑布流,

    基础功能:

    增删改查,安全(单张限流),

    常见问题:

    • fs文件读取到内容,但是替换到ctx.body上是空的,页面访问时404或者空值

    参考资料:https://blog.csdn.net/gwdgwd123/article/details/84099727?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
    https://www.cnblogs.com/gsgs/p/7056658.html

    const read_routes = async (ctx, next) => {
        console.log(__dirname)
        var content = '';
        //  koa和express不一样 没有处理readFile 异步的中间件 需要自己加异步处理函数
        await new Promise((resolve, reject) => {
            fs.readFile(__dirname+'/demo', 'utf-8', function(err, data) {
                if (err) {
                    throw err
                    reject();
                } else {
                    content = data;
                    resolve()
                }
    
            });
        });
        ctx.body = content;
        console.log(ctx.body)
    };
    

    相关文章

      网友评论

          本文标题:nodejs+koa2构建自己的图库

          本文链接:https://www.haomeiwen.com/subject/cooiyhtx.html