• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript kubectl-object-model.Kubectl类代码示例发布时间:2022-05-25
下一篇:
TypeScript koa-router.use函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap