本文整理匯總了TypeScript中next類的典型用法代碼示例。如果您正苦於以下問題:TypeScript next類的具體用法?TypeScript next怎麽用?TypeScript next使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了next類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor() {
this.appPath = resolve(`${__dirname}/../app`); // path to next.js project (with the pages dir)
this.nextApp = next({
dir: this.appPath,
dev: process.env.NODE_ENV !== 'production'
});
this.expressApp = express();
this.setRoutes();
}
示例2: parseInt
import micro from 'micro'
import { parse } from 'url'
import * as next from 'next'
import backend from '@epic/backend'
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const server = micro(async (req, res) => {
const parsedUrl = parse(req.url, true)
const maybeBackend = await backend(dev, req, res, parsedUrl)
if (maybeBackend) {
return maybeBackend
}
return handle(req, res, parsedUrl)
})
app.prepare().then(() => {
server.listen(port, err => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})
示例3: next
// TODO: Convert the custom server implementation to typescript.
import * as compression from 'compression';
import * as express from 'express';
import * as next from 'next';
import { parse } from 'url';
import routes from './routes';
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dir: 'src', dev });
app.prepare().then(() => {
const server = express();
if (process.env.NODE_ENV === 'production') {
// Add gzip compression.
server.use(compression());
}
// Catch any requests to static files not served by next.
server.use(/^(?!\/_next)(.*)\.(.*)/, (req, res) => {
app.render404(req, res, parse(req.url, true));
});
server.use(routes.getRequestHandler(app));
server.listen(process.env.PORT);
});
示例4: Next
import * as Koa from 'koa';
import * as Router from 'koa-router';
import * as Next from 'next';
import routes from './routes';
const port = 3000;
const dev = process.env.NODE_DEV !== 'production';
const app = Next({ dev, quiet: true });
const handle = routes.getRequestHandler(app);
app.prepare().then(() => {
const server = new Koa();
const router = new Router();
router.get('*', async ctx => {
await handle(ctx.req, ctx.res);
ctx.respond = false;
});
server.use(async (ctx, next) => {
ctx.res.statusCode = 200;
await next();
});
server.use(router.routes());
server.listen(port);
});