router.get('/', async (ctx) => {
await ctx.render('index', {title: 'Авторизация'});
});
const Koa = require('koa'),
Router = require('koa-router'),
logger = require('koa-logger'),
views = require('koa-views'),
bodyParser = require('koa-bodyparser'),
app = new Koa(),
router = new Router();
app.use(logger());
app.use(bodyParser());
app.use(views(__dirname + '/views', {extension: 'pug'}));
router.get('/', async (ctx) => {
await ctx.render('index', {title: 'Авторизация'});
});
module.exports = app;
const Koa = require('koa'),
Router = require('koa-router'),
logger = require('koa-logger'),
views = require('koa-views'),
bodyParser = require('koa-bodyparser'),
app = new Koa(),
router = new Router();
app.use(logger());
app.use(bodyParser());
app.use(views(__dirname, {extension: 'html'}));
router.get('/', async (ctx) => {
await ctx.render('index', {title: 'Авторизация'});
});
app.use(router.routes());
app.listen(3001);
<h1>Hello</h1>
├── koa@2.4.1
├── koa-bodyparser@4.2.0
├── koa-logger@3.1.0
├── koa-router@7.3.0
└── koa-views@6.1.2
const Koa = require('koa'),
Router = require('koa-router'),
logger = require('koa-logger'),
views = require('koa-views'),
serve = require('koa-static-server'),
app = new Koa(),
router = new Router();
app.use(logger());
app.use(bodyParser());
app.use(serve({rootDir: __dirname + 'public', rootPath: '/public'}));
app.use(views(__dirname + '/views', {extension: 'pug'}));
routers('/', 'login', {title: 'Авторизация'});
routers('/registration', 'registration', {title: 'Регистрация'});
function routers(path, page, object) {
router.get(path, async (ctx) => {
await ctx.render(page, object);
})
}
app.use(router.routes());
module.exports = app;
public/
| javascript/
|| modal.js
|| form.js
| styles/
|| style.css
views/
| layout.pug
| index.pug
app.js
doctype html
html
head
title=title
meta(name="viewport", content="width=device-width, initial-scale=1.0")
link(rel='stylesheet', href='styles/style.css')
script(src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js")
script(src="/javascript/modal.js")
script(src="/javascript/form.js")
....