Commit ·
40641db
1
Parent(s): afc2f8a
增加通用路由
Browse files
ndcc/server/lib/index.js
CHANGED
|
@@ -707,23 +707,6 @@ exports.plugin = {
|
|
| 707 |
}
|
| 708 |
});
|
| 709 |
|
| 710 |
-
// // 会覆盖路由配置,注释掉
|
| 711 |
-
// //Set api route
|
| 712 |
-
// server.route({
|
| 713 |
-
// method: ['POST','GET'],
|
| 714 |
-
// path: '/api/{action*}',
|
| 715 |
-
// options:{auth: 'auth'},
|
| 716 |
-
// handler: async (request,h) => {
|
| 717 |
-
// try {
|
| 718 |
-
// const {req,res} = await new Basic(request,server).init();
|
| 719 |
-
// await handler(req, res);
|
| 720 |
-
// return h.close;
|
| 721 |
-
// } catch (e) {
|
| 722 |
-
// Error(e);
|
| 723 |
-
// }
|
| 724 |
-
// }
|
| 725 |
-
// });
|
| 726 |
-
|
| 727 |
// //web routing must be placed last
|
| 728 |
// server.route({
|
| 729 |
// method: 'GET',
|
|
|
|
| 707 |
}
|
| 708 |
});
|
| 709 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 710 |
// //web routing must be placed last
|
| 711 |
// server.route({
|
| 712 |
// method: 'GET',
|
ndcc/server/plugins/route.js
CHANGED
|
@@ -222,7 +222,6 @@ exports.plugin = {
|
|
| 222 |
})
|
| 223 |
return arr;
|
| 224 |
}
|
| 225 |
-
|
| 226 |
|
| 227 |
//set custom api and web route
|
| 228 |
for(let item of ['api','web']){
|
|
@@ -247,5 +246,42 @@ exports.plugin = {
|
|
| 247 |
});
|
| 248 |
})
|
| 249 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
}
|
| 251 |
};
|
|
|
|
| 222 |
})
|
| 223 |
return arr;
|
| 224 |
}
|
|
|
|
| 225 |
|
| 226 |
//set custom api and web route
|
| 227 |
for(let item of ['api','web']){
|
|
|
|
| 246 |
});
|
| 247 |
})
|
| 248 |
}
|
| 249 |
+
|
| 250 |
+
//api通用路由
|
| 251 |
+
server.route({
|
| 252 |
+
method: ['GET'],
|
| 253 |
+
path: '/api/{action*}',
|
| 254 |
+
options:{auth: 'auth'},
|
| 255 |
+
handler: async (request,h)=>{
|
| 256 |
+
try {
|
| 257 |
+
request.raw.req.url = `/api/routes/${request.params.action}`;
|
| 258 |
+
const {req,res} = await new Basic(request,server).init();
|
| 259 |
+
await handler(req, res);
|
| 260 |
+
return h.close;
|
| 261 |
+
} catch (e) {
|
| 262 |
+
Error(e)
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
});
|
| 266 |
+
|
| 267 |
+
// web 通用路由
|
| 268 |
+
server.route({
|
| 269 |
+
method: 'GET',
|
| 270 |
+
path: '/{action*}',
|
| 271 |
+
handler: async (request, h) => {
|
| 272 |
+
try {
|
| 273 |
+
const url = request.url;
|
| 274 |
+
if (/^\/(workbox|worker|fallback)-\w+\.js$/.test(url.pathname)) { //处理pwa
|
| 275 |
+
return h.file(Path.join(process.cwd(), `pwa${url.pathname}`));
|
| 276 |
+
}else{
|
| 277 |
+
request.url.pathname = `/web/${request.params.action}`;
|
| 278 |
+
return await nextHandlerWrapper(request,h);
|
| 279 |
+
}
|
| 280 |
+
} catch (e) {
|
| 281 |
+
Error(e.message,'plugins')
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
});
|
| 285 |
+
|
| 286 |
}
|
| 287 |
};
|
src/pages/admin/ZhIS8NlvqEJ2bubJ/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import style from './style.module.scss';
|
| 2 |
import Container from './style';
|
| 3 |
-
export default function App() {
|
|
|
|
| 4 |
return (
|
| 5 |
<Container>
|
| 6 |
首页待编辑1test
|
|
|
|
| 1 |
import style from './style.module.scss';
|
| 2 |
import Container from './style';
|
| 3 |
+
export default function App(props) {
|
| 4 |
+
console.log(props,'--')
|
| 5 |
return (
|
| 6 |
<Container>
|
| 7 |
首页待编辑1test
|
src/pages/api/routes/test8/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default async (req,res)=>{
|
| 2 |
+
|
| 3 |
+
const {send,reply,error,isGet,db,user,mongo,query,payload,socket,remoteAddress,method,plugins} = await req.ctx();
|
| 4 |
+
try{
|
| 5 |
+
send('test8');
|
| 6 |
+
}catch (e){
|
| 7 |
+
console.log('err')
|
| 8 |
+
error(e)
|
| 9 |
+
}
|
| 10 |
+
};
|
src/pages/api/routes/test9/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default async (req,res)=>{
|
| 2 |
+
|
| 3 |
+
const {send,reply,error,isGet,db,user,mongo,query,payload,socket,remoteAddress,method,plugins} = await req.ctx();
|
| 4 |
+
try{
|
| 5 |
+
send('test9');
|
| 6 |
+
}catch (e){
|
| 7 |
+
console.log('err')
|
| 8 |
+
error(e)
|
| 9 |
+
}
|
| 10 |
+
};
|
src/pages/web/index1/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
export async function getServerSideProps({req,res}) {
|
| 3 |
+
return {
|
| 4 |
+
props: {}, // will be passed to the page component as props
|
| 5 |
+
}
|
| 6 |
+
}
|
| 7 |
+
export default () =>{
|
| 8 |
+
|
| 9 |
+
return 'index1'
|
| 10 |
+
}
|