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

TypeScript koa-static类代码示例

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

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



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

示例1: Koa

import * as Koa from 'koa'
import * as serve from 'koa-static'
import * as http from 'http'
import * as path from 'path'

const app = new Koa()

app.use(serve(path.join(__dirname, '')))

http.createServer(app.callback()).listen(3000, () => {
    console.log(`http server listening on port: 3000`)
})
开发者ID:YimYijet,项目名称:WebTest,代码行数:12,代码来源:a.ts


示例2: SocketHandler

import * as Koa from 'koa'
import * as serve from 'koa-static'
import { Server } from 'ws'
import SocketHandler from './socketHandler'

const app = new Koa();

app.use(serve('./public'));

const wss = new Server({server: app.listen(3000)});

new SocketHandler(wss);

console.log('application is running on port 3000');
开发者ID:NanaMorse,项目名称:mindmap,代码行数:14,代码来源: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: CompositeDisposable

	run() {
		this.app_.init(this);
		this.diposable_ = new CompositeDisposable();
		this.sessionManager_ = new SessionManager(() => { 
			this.app_.createSessionData() });
		this.connections_ = [];

		const koaApp = new Koa();
		koaApp.use(this.sessionManager_.asKoaMiddleware());
		koaApp.use(koaStatic("static", {}));
		const port = 3003;
		console.log(`start listen at ${port}`);

		const httpServer = http.createServer(koaApp.callback());

		const webSocketServer = new WebSocketServer({
			httpServer: httpServer 
			});
		webSocketServer.on("request", (request: WebSocketRequest) => {
			let sid: string = null;
			request.cookies.forEach((cookie) => {
				if (cookie.name == "sid") {
					sid = cookie.value;
					return;
				}
			});

			if (sid == null) {
				request.reject(403, "no sid");
				return;
			}

			let session = this.sessionManager_.openSession(sid);
			if (session == null) {
				request.reject(403, "invalid session id");
				return;
			}
			
			const socket = new SocketImpl(request.accept(null, null));
			this.createConnection(socket, sid);
		});

		httpServer.listen(port);
	}
开发者ID:omochi,项目名称:national-economy,代码行数:44,代码来源:Engine.ts


示例6: Compose

export default function middleware(context: Koa) {
    const ctrlRouter = new WebApiRouter();
    return Compose(
        [
            asyncInit(),
            errorHandle(),
            KoaStatic(Path.join(__dirname, '../public'), { gzip: true }),
            Session({
                cookie: {
                    maxAge: SessionService.maxAge
                }
            }),
            sessionHandle(),
            Bodyparser({ jsonLimit: '50mb' }),
            ctrlRouter.router('../build/controllers', 'api'),
            routeFailed(),
        ]
    );
}
开发者ID:winken168,项目名称:Hitchhiker,代码行数:19,代码来源:middleware.ts


示例7: Koa

import * as convert from 'koa-convert'
import * as webpack from 'webpack'
import * as historyApiFallback from 'koa-connect-history-api-fallback'
import * as path from 'path'
import * as fs from 'fs-extra'
import * as _debug from 'debug'
import configs from '../configs'
import webpackDevMiddleware from './middleware/webpack-dev'
import webpackHMRMiddleware from './middleware/webpack-hmr'
import webpackConfig from './webpack.client'

const debug = _debug('app:server')
const app = new Koa()
const __DEV__ = configs.env === 'development'

app.use(convert(historyApiFallback({
  verbose: false,
})))

if (__DEV__) {
  // Enable webpack-dev and webpack-hot middleware
  const compiler = webpack(webpackConfig as any)
  const { publicPath } = webpackConfig.output
  app.use(webpackDevMiddleware(compiler, publicPath))
  app.use(webpackHMRMiddleware(compiler))
} else {
  app.use(convert(KoaStatic(configs.outDir)))
}

export default app
开发者ID:stefaniepei,项目名称:react-redux-scaffold,代码行数:30,代码来源:app.ts


示例8: 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


示例9: constructor

    md.remove(ctx.request.body.id);
    ctx.body = true;
});
router.post('/edit', (ctx, next) => {
    ctx.body = md.getFile(ctx.request.body.id);
});
router.post('/updateCont', (ctx, next) => {
    md.setFile(ctx.request.body.id, ctx.request.body.cont);
    ctx.body = true;
})
router.post('/updateTitle', (ctx, next) => {
    const
        id = ctx.request.body.id,
        title = ctx.request.body.title;
    ctx.body = md.setTitle(id, title);
});
koa
    .use(body({}))
    .use(router.routes())
    .use(router.allowedMethods())
    .use(Static(__dirname + '/view'))
    .use(Static(path.join(__dirname ,'../../')));

export class Admin {
    constructor(port) {
        koa.listen(port, (e) => {
            console.log(`Admin is run. port:${port}`);
            // open('http://localhost:' + port);
        });
    }
}
开发者ID:zoeDylan,项目名称:zoeDylan.github.io,代码行数:31,代码来源:index.ts


示例10: next

  if (ctx.path === '/favicon.ico') return
  ctx.session.views = (ctx.session.views || 0) + 1
  let app: any = ctx.app
  if (ctx.session.fullname) app.counter.users[ctx.session.fullname] = true
})
app.use(cors({
  credentials: true
}))
app.use(async(ctx, next) => {
  await next()
  if (typeof ctx.body === 'object' && ctx.body.data !== undefined) {
    ctx.type = 'json'
    // ctx.body.path = ctx.path
    ctx.body = JSON.stringify(ctx.body, undefined, 2)
  }
})
app.use(async(ctx, next) => {
  await next()
  if (ctx.request.query.callback) {
    let body = typeof ctx.body === 'object' ? JSON.stringify(ctx.body, undefined, 2) : ctx.body
    ctx.body = ctx.request.query.callback + '(' + body + ')'
    ctx.type = 'application/x-javascript'
  }
})

app.use(serve('public'))
app.use(serve('test'))
app.use(body())
app.use(router.routes())

export default app
开发者ID:zerolugithub,项目名称:rap2-delos,代码行数:31,代码来源:app.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript koa-views类代码示例发布时间:2022-05-28
下一篇:
TypeScript koa-session类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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