當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript next類代碼示例

本文整理匯總了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();
  }
開發者ID:benangmerah,項目名稱:benangmerah,代碼行數:11,代碼來源:Server.ts

示例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}`)
  })
})
開發者ID:stipsan,項目名稱:epic,代碼行數:28,代碼來源:server.ts

示例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);
});
開發者ID:fubhy,項目名稱:drupal-decoupled-app,代碼行數:28,代碼來源:index.ts

示例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);
});
開發者ID:Ushinji,項目名稱:next_sample,代碼行數:30,代碼來源:server.ts


注:本文中的next類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。