當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript koa-mount類代碼示例

本文整理匯總了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");
開發者ID:DavidM77,項目名稱:DefinitelyTyped,代碼行數:22,代碼來源:koa-mount-tests.ts

示例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;
開發者ID:coderfox,項目名稱:Another-SS-Panel,代碼行數:15,代碼來源:index.ts

示例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())
    }
開發者ID:borestad,項目名稱:playground,代碼行數:22,代碼來源:config.webpack.serve.ts

示例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);
}
開發者ID:giggio,項目名稱:transempregos-portal,代碼行數:23,代碼來源:staticFiles.ts

示例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)

}
開發者ID:Edward-Lombe,項目名稱:elm-electron,代碼行數:21,代碼來源:server.ts

示例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;
開發者ID:coderfox,項目名稱:Another-SS-Panel,代碼行數:30,代碼來源:server.ts

示例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() {
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:30,代碼來源:index.ts

示例8: mount

 protected mount() {
   this.app.use(_mount(this.mount_path, this.router.middleware()));
 }
開發者ID:HackrLabs,項目名稱:HakrPass,代碼行數:3,代碼來源:base-handler.ts


注:本文中的koa-mount類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。