aircode-app
v0.2.0
Published
A simple webapp framework for AirCode.
Downloads
4
Readme
AirCode App
A simple webapp framework for AirCode.
Usage
Install aircode-app as dependencies.
Entry js file:
// @see https://docs.aircode.io/guide/functions/
const App = require('aircode-app');
const app = new App();
app.use(async (ctx, next) => {
await next();
console.log('foobar');
});
app.use(async (ctx, next) => {
const {params} = ctx;
ctx.set('content-type', 'text/html');
ctx.body = app.display('./hello.html', {params});
});
module.exports = app.run();
- HTML Templates & JS & CSS:
<!-- hello.html -->
<!DOCTYPE html>
<html lang="en">
${app.display('./head.tpl')}
<body>
<h1>${JSON.stringify(params)}</h1>
</body>
${app.display('./footer.tpl')}
</html>
<!-- head.tpl -->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
${app.file('./style.css')}
</style>
</head>
<!-- footer.tpl -->
<script>
${app.file('./script.js')}
</script>
/* style.css */
body {
background-color: #000;
color: #fff;
}
// script.js
console.log('hello world');
You may use this template for startup.
That's all.
Enjoy it!