本文整理汇总了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;
示例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));
}
示例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;
}
示例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();
示例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) {
示例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']
}
示例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);