Skip to content

Commit

Permalink
feat: statics done
Browse files Browse the repository at this point in the history
  • Loading branch information
刘江虹 committed Sep 30, 2021
1 parent e3128d9 commit 8b1f63e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 2 deletions.
7 changes: 6 additions & 1 deletion example/config/config.development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ export default app => {
extension: 'ejs'
},

//koa-bodyparser配置
// koa-bodyparser配置
bodyparser: {

},

// koa-static配置
static: {

}
}
Expand Down
10 changes: 10 additions & 0 deletions example/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.h1 {
padding: 20px;
color: #111;
text-align: center;
background: #f0f0f0;
}

.div {
text-align: center;
}
Binary file added example/static/image/koa2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions example/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>index</title>
<link rel="stylesheet" href="/css/style.css" />
</head>
<body>
<h1 class="h1">this is koa static server</h1>
<div class="div">
<img src="/image/koa2.jpg" />
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions lib/core/hooks/static.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import koaStatic from 'koa-static';
import path from 'path';

export default async (app) => {
const staticConfig = app.config.static;
app.use(koaStatic(path.join(app.appPath, './static'), staticConfig))
}

2 changes: 1 addition & 1 deletion lib/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Koa from 'koa';
import path from 'path';
import { getHooks, deepMerge } from './utils'
import { Hook, App } from './types';
const hooks = [ 'view', 'bodyparser', 'login', 'custom-middlewares' ,'cors', 'router', 'lift' ];
const hooks = ['static', 'view', 'bodyparser', 'login', 'custom-middlewares' ,'cors', 'router', 'lift' ];

type Params = {
appPath: string;
Expand Down
19 changes: 19 additions & 0 deletions lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"koa": "^2.13.3",
"koa-bodyparser": "^4.3.0",
"koa-compose": "^4.1.0",
"koa-static": "^5.0.0",
"koa-views": "^7.0.1",
"lodash": "^4.17.21",
"pug": "^3.0.2",
Expand Down

0 comments on commit 8b1f63e

Please sign in to comment.