美文网首页
egg 后端拦截路由

egg 后端拦截路由

作者: 冷r | 来源:发表于2019-09-23 20:57 被阅读0次

    'use strict';
    const fs = require('fs');
    const path = require('path');
    const writeRoute= [ 'login', 'home/' ]

    module.exports = () => {
    return async function router(ctx, next) {
    const { url } = ctx.request;
    const isRoute = writeRoute.some(router => {
    const reg = new RegExp(^\/${router});
    return reg.test(url);
    });
    if (isRoute) {
    const filename = path.join(
    process.cwd(),
    '/app/public/static/index.html'
    );
    const data = fs.readFileSync(filename, 'utf-8');
    ctx.body = data;
    await next();
    } else {
    await next();
    }
    };
    };

    相关文章

      网友评论

          本文标题:egg 后端拦截路由

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