index.js 363 B

1234567891011121314151617181920
  1. import Koa from 'koa';
  2. import { DBMiddleware } from './db/index.js';
  3. const app = new Koa();
  4. app.use(DBMiddleware);
  5. app.use(async (ctx) => {
  6. let res = await ctx.execute('select * from users;');
  7. ctx.body = {
  8. code: 0,
  9. msg: '数据查询成功',
  10. data: res,
  11. };
  12. });
  13. app.listen(4000, () => {
  14. console.log('Server is running at port:', 4000);
  15. });