0.2.0 • Published 12 months ago

aircode-app v0.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

AirCode App

A simple webapp framework for AirCode.

Usage

  1. Install aircode-app as dependencies.

  2. 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();
  1. 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!

0.1.0

12 months ago

0.2.0

12 months ago

0.0.1

1 year ago