本文整理汇总了TypeScript中koa-mount类的典型用法代码示例。如果您正苦于以下问题:TypeScript koa-mount类的具体用法?TypeScript koa-mount怎么用?TypeScript koa-mount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了koa-mount类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Koa
import * as Koa from "koa";
import * as mount from "koa-mount";
const a = new Koa();
a.use((next) => {
this.body = "Hello";
});
const b = new Koa();
b.use((next) => {
this.body = "World";
});
const app = new Koa();
app.use(mount("/hello", a));
app.use(mount("/world", b));
app.listen(3000);
console.log("listening on port 3000");
示例2: Koa
"use strict";
import * as Koa from "koa";
import * as mount from "koa-mount";
import * as serve from "koa-static";
import { join } from "path";
import server from "./server/server";
const app = new Koa();
app.use(mount(server));
app.use(mount("/app", serve(join(__dirname, "client/build"))));
export default app;
示例3: webpackServeWaitpage
add: (app, middleware, options) => {
app.use(
webpackServeWaitpage(options, {
template: fs.readFileSync(
path.join(config.paths.gitRoot, 'webpack', 'config', 'waitpage.ejs'),
'utf8'
)
})
)
app.use(mount('/node_modules', serve(config.paths.nodeModules)))
app.use(
mount('/currencies', serve(path.join(config.paths.vendor, 'game-currency-formats', 'src')))
)
// Make sure the usage of webpack-serve-waitpage will be before the following commands if exists
middleware.webpack()
middleware.content()
app.use(router.routes())
}
示例4: serveStatic
export function serveStatic(): Koa.Middleware {
const middlewares: Array<Koa.Middleware> = [];
const distPublicPath = path.resolve(__dirname, '../public');
middlewares.push(mount('/dist/public', serve(distPublicPath)));
middlewares.push(favicon(path.resolve(distPublicPath, 'images', 'icons', 'favicon.ico')));
if (!isProdEnv) {
const publicPath = path.resolve(__dirname, '../../public');
middlewares.push(mount('/public', serve(publicPath)));
const nodeModulesPath = path.resolve(__dirname, '../../node_modules');
middlewares.push(mount('/node_modules', serve(nodeModulesPath)));
}
middlewares.push(async (ctx: Koa.Context, next: () => Promise<any>) => {
const url = ctx.originalUrl;
if (url.substr(0, 6) === '/dist/'
|| url.substr(0, 14) === '/node_modules/'
|| url.substr(0, 8) === '/public/') {
ctx.status = 404;
} else {
await next();
}
});
return compose(middlewares);
}
示例5: initialize
export function initialize() {
const httpServer = http.createServer(app.callback())
log('Starting HTTP server')
// We serve the root of the application at the moment
app.use(mount('/', serveRoot()))
// Renders the main html wrapper for the index
app.use(context => {
context.body = '<!DOCTYPE html>' + renderToString(createElement(HTMLPage))
})
websocket.initialize(httpServer)
httpServer.listen(3000)
}
示例6: Error
neq: function fnb(this: any, lvalue: any, rvalue: any, options: any) {
if (arguments.length < 3) {
throw new Error("Handlebars Helper equal needs 2 parameters");
}
if (lvalue !== rvalue) {
return options.fn(this);
} else {
return options.inverse(this);
}
},
},
},
})
);
// TODO: logger
app.use(bodyParser());
app.use(
session({
store: new sessionStore(dbPath),
})
);
app.use(
mount("/js", serve(`${__dirname}/../node_modules/material-design-lite/dist`))
);
app.use(
mount("/css", serve(`${__dirname}/../node_modules/material-design-lite/dist`))
);
app.use(router.routes()).use(router.allowedMethods());
export default app;
示例7: next
// Compress response
app.use(compress({
flush: zlib.constants.Z_SYNC_FLUSH
}));
// HSTS
// 6months (15552000sec)
if (config.url.startsWith('https')) {
app.use(async (ctx, next) => {
ctx.set('strict-transport-security', 'max-age=15552000; preload');
await next();
});
}
app.use(mount('/api', require('./api')));
app.use(mount('/files', require('./file')));
// Init router
const router = new Router();
// Routing
router.use(activityPub.routes());
router.use(webFinger.routes());
// Register router
app.use(router.routes());
app.use(mount(require('./web')));
function createServer() {
示例8: mount
protected mount() {
this.app.use(_mount(this.mount_path, this.router.middleware()));
}