當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。