nodejs一般的に使用されるサンプルフレーム

さらに

const Koa = require('koa');
const router = require('koa-router')();
const app = new Koa();
const mount = require('koa-mount');
const fs=require("fs");
const bodyParser = require('koa-bodyparser');
var cors = require('koa2-cors');

//允许跨域
app.use(cors());
//允许post请求
app.use(bodyParser());


////读取指定文件夹里所有json文件名称
var fn_getModelLocs=async (ctx,next)=>{
    await getDirJsons(ctx,modelPath);
};


//功能函数
////模型数据的路径
let modelPath='modelDatas/';
////读取指定文件夹里所有json文件名称
function getDirJsons(ctx,path) {
    let jsonFiles=[];

    let files=fs.readdirSync(path);
    files.forEach((item,index)=>{
        jsonFiles.push(item.replace('.json',''));
    });
    ctx.body=jsonFiles;
}

//路由
router.get('/',async ctx => {
    ctx.body = 'Hello Server';
});
app.use(mount('/getModelLocs',fn_getModelLocs));

おすすめ

転載: www.cnblogs.com/mrlwc/p/12082273.html