保存
This commit is contained in:
50
mail-worker/src/hono/hono.js
Normal file
50
mail-worker/src/hono/hono.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Hono } from 'hono';
|
||||
|
||||
const app = new Hono();
|
||||
import initDB from '../init/init-db';
|
||||
import initCache from '../init/init-cache';
|
||||
import verify from '../security/security';
|
||||
import result from '../model/result';
|
||||
import { cors } from 'hono/cors';
|
||||
|
||||
app.use('*', cors());
|
||||
|
||||
let initStatus = true;
|
||||
app.use('*', async (c, next) => {
|
||||
if (initStatus) {
|
||||
await initDB(c);
|
||||
initStatus = false;
|
||||
}
|
||||
await next();
|
||||
});
|
||||
|
||||
|
||||
let initCacheStatus = true;
|
||||
app.use('*', async (c, next) => {
|
||||
if (initCacheStatus) {
|
||||
await initCache(c);
|
||||
initCacheStatus = false;
|
||||
}
|
||||
await next();
|
||||
});
|
||||
|
||||
|
||||
app.use('*', async (c, next) => {
|
||||
if(await verify(c)) {
|
||||
await next();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
app.onError((err, c) => {
|
||||
if (err.name === 'BizError') {
|
||||
console.log(err.message);
|
||||
}else {
|
||||
console.error(err);
|
||||
}
|
||||
return c.json(result.fail(err.message, err.code));
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
||||
|
||||
9
mail-worker/src/hono/webs.js
Normal file
9
mail-worker/src/hono/webs.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import app from './hono';
|
||||
import '../api/email-api';
|
||||
import '../api/user-api';
|
||||
import '../api/login-api';
|
||||
import '../api/setting-api';
|
||||
import '../api/account-api';
|
||||
import '../api/star-api';
|
||||
import '../api/test-api';
|
||||
export default app;
|
||||
Reference in New Issue
Block a user