当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript koa-static.default函数代码示例

本文整理汇总了TypeScript中koa-static.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: require

if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') require('dotenv').config();

import * as Koa from 'koa';
import * as chalk from 'chalk';
import {logger} from './configs';
import {router} from './routes';
import {middleware} from './middlewares';
import * as S from './services';
import { startWorker } from './workers';
let serve = require('koa-static');

const app = new Koa();


const port = process.env.PORT || 5555;

// 异步worker
startWorker();

S.startService();

app.use(middleware())
    .use(router().routes())
    .use(serve('.'));

app.listen(port, async () => {
    console.log(chalk.black.bgGreen.bold(`Listening on port ${port}`));
});

export default app;
开发者ID:zcg331793187,项目名称:DownloadYouLike,代码行数:30,代码来源:index.ts

示例2: init

  static init(application, router) {
    let _root = process.cwd();
    let _nodeModules = "/node_modules";
    let _jspmPackages = "/jspm_packages";
    let _clientFiles = (process.env.NODE_ENV === "production") ? "/client/dist" : "/client/dev";

    application.use(bodyParser());
    application.use(router.routes());
    application.use(serve(_root + _nodeModules));
    application.use(serve(_root + _jspmPackages));
    application.use(serve(_root + _clientFiles));
  }
开发者ID:bernardbr,项目名称:generator-ng-fullstack,代码行数:12,代码来源:routes.conf.ts

示例3: createServer

function createServer() {
  const app = new Koa();
  app.use(bodyParser());
  app.use(cors());
  app.use(staticFiles(path.join(__dirname, 'public')));

  const router = new Router();
  router.get('/api/animals', async (ctx) => {
    ctx.body =  [
      {id: 1, name: 'cat'},
      {id: 2, name: 'dog'},
      {id: 3, name: 'fish'}
    ];
  });

  app.use(async (ctx, next) => {
    try {
      await next();
    } catch (err) {

      const error = {
        errorType: 'UNHANDLED_ERROR',
        message: err.message,
        stack: err.stack
      };

      ctx.body = error;
      // tslint:disable-next-line:no-console
      console.error(error);
    }
  });

  app
  .use(router.routes())
  .use(router.allowedMethods());

  return app;
}
开发者ID:stevejhiggs,项目名称:macgyver,代码行数:38,代码来源:server.ts

示例4: koaCompress

      <title>GenieACS</title>
      <link rel="shortcut icon" type="image/png" href="favicon.png" />
      <link rel="stylesheet" href="app.css">
    </head>
    <body>
      <script>
        window.clientConfig = ${JSON.stringify({
          ui: localCache.getUiConfig(ctx.state.configSnapshot)
        })};
        window.username = ${JSON.stringify(
          ctx.state.user ? ctx.state.user.username : ""
        )};
        window.permissionSets = ${JSON.stringify(permissionSets)};
      </script>
      <script src="app.js"></script>
    </body>
  </html>
  `;
});

koa.use(
  koaCompress({
    flush: Z_SYNC_FLUSH
  })
);

koa.use(router.routes());
koa.use(koaStatic("./public"));

export const listener = koa.callback();
开发者ID:zaidka,项目名称:genieacs,代码行数:30,代码来源:ui.ts

示例5: function

namespace MongoSetup
{
    mongoose.connect('mongodb://localhost/dashboard');
    var db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', function(callback: any) { console.log("connection to mongodb: ok.") });
}

// APP
var app = koa();
var server = http.createServer(app.callback()).listen(confAppPort);
var io = socketio.listen(server);

namespace PageSetup
{
   app.use(koaStatic("build/client"));
}

var comments: any = { };

io.on('connection', socket =>
{
    socket.on("get-comments", (id: string) => {
        CommentsDB.portal.findOne({"uid": id}, (err: any, res: any) => {
            socket.emit("get-comments-success", res == null ? "" : res.content);
        });
    });

    socket.on("save-comments", (id: string, content: string) => {
        CommentsDB.portal.findOne({"uid": id}, (err: any, res: any) => {
            if (res == null) {
开发者ID:Amtrix,项目名称:WebDashboard,代码行数:31,代码来源:main.ts

示例6: next

    maxAge: 30,
    buffer: true
};
serveStaticOptions = null;

const app: Koa = new Koa();
app.use(compress({
    flush: zlib.Z_SYNC_FLUSH
}));
app.use((ctx: Koa.Context, next)=> {
    return next().then(() => {
        ctx.set('Cache-Control', 'max-age=31536000'); // 1 year
    });
    // ctx.set('Cache-Control', 'no-cache');
});
app.use(serveStatic('.www', serveStaticOptions));

var mvc = new Mvc();
mvc.registerAreas(__dirname, ['/admin', '/home'], {
    views: {
        extension: 'pug',
        engine: 'pug',
        templateOptions: {
            basedir: '.dist/scripts/server/app',
            meta: {
                manifest: manifest,
            },
            render: {
                scriptSource: bundle => manifest[bundle]['js'],
                styleSource: bundle => manifest[bundle]['css']
            }
开发者ID:pbalaga,项目名称:craftdb,代码行数:31,代码来源:app.ts

示例7: next

"use strict";

import {resolve} from "path";

import * as Koa from "koa";
const convert = require('koa-convert');
const statics = require('koa-static');

import router from "./config/routes";

const app = new Koa();

app.use(async function (ctx,next) {
    try {
        await next();
    } catch (err) {
        console.log(err);
    }
});

app.use(convert(statics(resolve(__dirname,'../dist'))));

app.use(router.routes());

app.listen(process.env.PORT || 3000);
开发者ID:NextZeus,项目名称:cnode,代码行数:25,代码来源:app.ts


注:本文中的koa-static.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。