-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support custom fs module with same interface like 🐝 ..
- Loading branch information
1 parent
9fcef07
commit eb93c97
Showing
7 changed files
with
212 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*! | ||
* koa-ejs - example/app-with-custom-fs-module | ||
* | ||
* Copyright(c) 2022 3imed-jaberi <imed-jaberi@outlook.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
'use strict' | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
const Koa = require('koa') | ||
const render = require('..') | ||
const path = require('path') | ||
|
||
const app = new Koa() | ||
|
||
render(app, { | ||
root: path.join(__dirname, 'view'), | ||
fs: require('mz/fs'), | ||
layout: 'template', | ||
viewExt: 'html', | ||
cache: false, | ||
debug: false | ||
}) | ||
|
||
app | ||
.use(function (ctx, next) { | ||
ctx.state = ctx.state || {} | ||
ctx.state.now = new Date() | ||
ctx.state.ip = ctx.ip | ||
ctx.state.version = '2.0.0' | ||
return next() | ||
}) | ||
.use(async function (ctx) { | ||
const users = [{ name: 'Dead Horse' }, { name: 'Imed Jaberi' }, { name: 'Tom' }] | ||
await ctx.render('content', { users }) | ||
}) | ||
|
||
if (process.env.NODE_ENV === 'test') { | ||
module.exports = app.callback() | ||
} else { | ||
app.listen(7001) | ||
console.log('open http://localhost:7001') | ||
} | ||
|
||
app.on('error', function (err) { | ||
console.log(err.stack) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/*! | ||
* koa-ejs - example/app.js | ||
* | ||
* Copyright(c) 2017 dead_horse <dead_horse@qq.com> | ||
* MIT Licensed | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters