Skip to content

Commit

Permalink
feat: view done
Browse files Browse the repository at this point in the history
  • Loading branch information
刘江虹 committed Sep 30, 2021
1 parent 157bf33 commit 4072e68
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 3 deletions.
4 changes: 4 additions & 0 deletions example/config/config.development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default app => {


}
},
// koa-view模版配置
view: {
extension: 'ejs'
}
}
}
2 changes: 1 addition & 1 deletion example/controller/goods/getinfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
method: 'GET',
handler: (ctx) => {
handler: async (ctx) => {
ctx.body = "this is koa book."
}
}
7 changes: 5 additions & 2 deletions example/controller/user/getinfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export default {
method: 'GET',
handler: (ctx) => {
ctx.body = "my name is liujianghong."
handler: async (ctx) => {

await ctx.render('404', {
url: 'https://baidu.com',
})
}
}
27 changes: 27 additions & 0 deletions example/view/302.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<style>
html,body {text-align:left;font-size:1em;font-family:Courier,monospace;height:100%}
html,body,img,form,textarea,input,fieldset,div,p,div,ul,li,ol,dl,dt,dd,
h1,h2,h3,h4,h5,h6,pre,code{margin:0;padding:0}
ul,li{list-style:none}
a{text-decoration:none;font-weight:normal;font-family:inherit}
*{box-sizing:border-box}
*:active,*:focus{outline:0;-moz-outline-style:none}
h1,h2,h3,h4,h5,h6,h7{font-weight:normal;font-size:1em}
.clearfix:after{clear:both;content:"";display:block;visibility:hidden}
.wrap{min-height:100%;padding:60px 20px 100px;max-width:620px;margin:0 auto;}
.footer{margin-top:-40px;height:20px;text-align:center;font-size:12px;font-weight:bold}
.footer b{color: #F83F1D}
.wrap h1,.wrap h2,.wrap p{text-align:center}
.wrap h1{font-size:120px;line-height:120px;font-weight:bold;color: #5192b9;margin-top: 200px;}
.wrap h2{font-size:30px;line-height:30px;font-weight:bold;margin-top:20px}
.wrap p{margin-top:30px;font-size:20px;opacity:0.5;word-break:break-all;line-height:150%}
.wrap pre{margin-top:30px;overflow-x:auto;border:1px solid #E5E5E5;padding:20px;border-radius:2px}
</style>
<div class="wrap">
<h1>302</h1>
<h2>Moved Temporarily</h2>
<p>The page will redirect to "<a href="<%= url %>"><%= url %></a>"</p>
</div>
<div class="footer">with <b>♥</b> by lianjia-fe</div>
<script> location.replace(<%- JSON.stringify(url) %>) </script>

30 changes: 30 additions & 0 deletions example/view/403.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<style>
html,body {text-align:left;font-size:1em;font-family:Courier,monospace;height:100%}
html,body,img,form,textarea,input,fieldset,div,p,div,ul,li,ol,dl,dt,dd,
h1,h2,h3,h4,h5,h6,pre,code{margin:0;padding:0}
ul,li{list-style:none}
a{text-decoration:none;font-weight:normal;font-family:inherit}
*{box-sizing:border-box}
*:active,*:focus{outline:0;-moz-outline-style:none}
h1,h2,h3,h4,h5,h6,h7{font-weight:normal;font-size:1em}
.clearfix:after{clear:both;content:"";display:block;visibility:hidden}
.wrap{min-height:100%;padding:60px 20px 100px;max-width:620px;margin:0 auto;}
.footer{margin-top:-40px;height:20px;text-align:center;font-size:12px;font-weight:bold}
.footer b{color: #F83F1D}
.wrap h1,.wrap h2,.wrap p{text-align:center}
.wrap h1{font-size:120px;line-height:120px;font-weight:bold;color: #5192b9;margin-top: 200px;}
.wrap h2{font-size:30px;line-height:30px;font-weight:bold;margin-top:20px}
.wrap p{margin-top:30px;font-size:20px;opacity:0.5;word-break:break-all;line-height:150%}
.wrap pre{margin-top:30px;overflow-x:auto;border:1px solid #E5E5E5;padding:20px;border-radius:2px}
</style>
<div class="wrap">
<h1>403</h1>
<h2>Forbidden</h2>
<p>
<% if (typeof message !== 'undefined') { %>
<%= message %>
<% } else { %>
You don't have permission to see the page you're trying to reach.
<% } %>
</p>
</div>
30 changes: 30 additions & 0 deletions example/view/404.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<style>
html,body {text-align:left;font-size:1em;font-family:Courier,monospace;height:100%}
html,body,img,form,textarea,input,fieldset,div,p,div,ul,li,ol,dl,dt,dd,
h1,h2,h3,h4,h5,h6,pre,code{margin:0;padding:0}
ul,li{list-style:none}
a{text-decoration:none;font-weight:normal;font-family:inherit}
*{box-sizing:border-box}
*:active,*:focus{outline:0;-moz-outline-style:none}
h1,h2,h3,h4,h5,h6,h7{font-weight:normal;font-size:1em}
.clearfix:after{clear:both;content:"";display:block;visibility:hidden}
.wrap{min-height:100%;padding:60px 20px 100px;max-width:620px;margin:0 auto;}
.footer{margin-top:-40px;height:20px;text-align:center;font-size:12px;font-weight:bold}
.footer b{color: #F83F1D}
.wrap h1,.wrap h2,.wrap p{text-align:center}
.wrap h1{font-size:120px;line-height:120px;font-weight:bold;color: #5192b9;margin-top: 200px;}
.wrap h2{font-size:30px;line-height:30px;font-weight:bold;margin-top:20px}
.wrap p{margin-top:30px;font-size:20px;opacity:0.5;word-break:break-all;line-height:150%}
.wrap pre{margin-top:30px;overflow-x:auto;border:1px solid #E5E5E5;padding:20px;border-radius:2px}
</style>
<div class="wrap">
<h1>404</h1>
<h2>Not Found</h2>
<p>
<% if (typeof message !== 'undefined') { %>
<%= message %>
<% } else { %>
The page you were trying to reach doesn't exist.
<% } %>
</p>
</div>
30 changes: 30 additions & 0 deletions example/view/500.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<style>
html,body {text-align:left;font-size:1em;font-family:Courier,monospace;height:100%}
html,body,img,form,textarea,input,fieldset,div,p,div,ul,li,ol,dl,dt,dd,
h1,h2,h3,h4,h5,h6,pre,code{margin:0;padding:0}
ul,li{list-style:none}
a{text-decoration:none;font-weight:normal;font-family:inherit}
*{box-sizing:border-box}
*:active,*:focus{outline:0;-moz-outline-style:none}
h1,h2,h3,h4,h5,h6,h7{font-weight:normal;font-size:1em}
.clearfix:after{clear:both;content:"";display:block;visibility:hidden}
.wrap{min-height:100%;padding:60px 20px 100px;max-width:620px;margin:0 auto;}
.footer{margin-top:-40px;height:20px;text-align:center;font-size:12px;font-weight:bold}
.footer b{color: #F83F1D}
.wrap h1,.wrap h2,.wrap p{text-align:center}
.wrap h1{font-size:120px;line-height:120px;font-weight:bold;color: #5192b9;margin-top: 200px;}
.wrap h2{font-size:30px;line-height:30px;font-weight:bold;margin-top:20px}
.wrap p{margin-top:30px;font-size:20px;opacity:0.5;word-break:break-all;line-height:150%}
.wrap pre{margin-top:30px;overflow-x:auto;border:1px solid #E5E5E5;padding:20px;border-radius:2px}
</style>
<div class="wrap">
<h1>500</h1>
<h2>Internal Server Error</h2>
<p> Something isn't right here. </p>
<% if (typeof error !== 'undefined') { %>
<% if (error.stack && error.stack.indexOf(error.toString()) !== 0) { %>
<pre><%= error.toString().replace(/\x1b\[\d+m/g, '') %></pre>
<% } %>
<pre><%= error.stack.replace(/\x1b\[\d+m/g, '') %></pre>
<% } %>
</div>

0 comments on commit 4072e68

Please sign in to comment.