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

TypeScript micro.default函数代码示例

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

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



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

示例1: require

const micro = require('micro')
const server = micro()
const io = require('socket.io')(server, {
  transports: ['websocket']
})

import { SOCKET_IO_PORT } from '../shared/const'

const { Game } = require('./game')

const gameSettings = {
  field: [],
  width: 30,
  height: 10,
  bombCount: 30
}

const players = {}
const connections = {}
const games = {}
let game

const defaultNick = socket => `Guest ${socket.id}`

const broadcast = (event, data) =>
  Object.values(connections).forEach(connection => {
    // @ts-ignore
    connection.emit(event, data)
  })

io.on('connection', function(socket) {
开发者ID:NotBadDevs,项目名称:minesweepers,代码行数:31,代码来源:index.ts


示例2: createApp

function createApp(options: CreateAppOptions) {
  const graphqlOptions = (options && options.graphqlOptions) || { schema };
  const graphiqlOptions = (options && options.graphiqlOptions) || {
    endpointURL: '/graphql',
  };

  const graphqlHandler = microGraphql(graphqlOptions);
  const graphiqlHandler = microGraphiql(graphiqlOptions);

  return micro(
    router(
      get('/graphql', graphqlHandler),
      post('/graphql', graphqlHandler),
      put('/graphql', graphqlHandler),
      patch('/graphql', graphqlHandler),
      del('/graphql', graphqlHandler),
      head('/graphql', graphqlHandler),
      opts('/graphql', graphqlHandler),

      get('/graphiql', graphiqlHandler),
      post('/graphiql', graphiqlHandler),
      put('/graphiql', graphiqlHandler),
      patch('/graphiql', graphiqlHandler),
      del('/graphiql', graphiqlHandler),
      head('/graphiql', graphiqlHandler),
      opts('/graphiql', graphiqlHandler),

      (req, res) => send(res, 404, 'not found'),
    ),
  );
}
开发者ID:chentsulin,项目名称:apollo-server,代码行数:31,代码来源:microApollo.test.ts


示例3: createServer

async function createServer(options: object = {}): Promise<any> {
  const apolloServer = new ApolloServer({ typeDefs, resolvers });
  const service = micro(apolloServer.createHandler(options));
  const uri = await listen(service);
  return {
    service,
    uri,
  };
}
开发者ID:simonjoom,项目名称:react-native-project,代码行数:9,代码来源:ApolloServer.test.ts


示例4: run

async function run() {
  const server = micro((req, res) => {
    return handler(req, res, {
      public: 'public',
    });
  });
  await server.listen(9000);
  try {
    await backstop(process.argv[2], { docker: true });
  } catch (e) {
    // tslint:disable-next-line no-console
    console.error(e);
    process.exit(1);
  } finally {
    server.close();
  }
}
开发者ID:screendriver,项目名称:echooff.de,代码行数:17,代码来源:run.ts


示例5: it

      it('should handle file uploads', async function() {
        // XXX This is currently a failing test for node 10
        const NODE_VERSION = process.version.split('.');
        const NODE_MAJOR_VERSION = parseInt(NODE_VERSION[0].replace(/^v/, ''));
        if (NODE_MAJOR_VERSION === 10) return;

        const apolloServer = new ApolloServer({
          typeDefs: gql`
            type File {
              filename: String!
              mimetype: String!
              encoding: String!
            }

            type Query {
              uploads: [File]
            }

            type Mutation {
              singleUpload(file: Upload!): File!
            }
          `,
          resolvers: {
            Query: {
              uploads: () => {},
            },
            Mutation: {
              singleUpload: async (_, args) => {
                expect((await args.file).stream).toBeDefined();
                return args.file;
              },
            },
          },
        });
        const service = micro(apolloServer.createHandler());
        const url = await listen(service);

        const body = new FormData();
        body.append(
          'operations',
          JSON.stringify({
            query: `
              mutation($file: Upload!) {
                singleUpload(file: $file) {
                  filename
                  encoding
                  mimetype
                }
              }
            `,
            variables: {
              file: null,
            },
          }),
        );
        body.append('map', JSON.stringify({ 1: ['variables.file'] }));
        body.append('1', fs.createReadStream('package.json'));

        try {
          const resolved = await fetch(`${url}/graphql`, {
            method: 'POST',
            body: body as any,
          });
          const text = await resolved.text();
          const response = JSON.parse(text);

          expect(response.data.singleUpload).toEqual({
            filename: 'package.json',
            encoding: '7bit',
            mimetype: 'application/json',
          });
        } catch (error) {
          // This error began appearing randomly and seems to be a dev
          // dependency bug.
          // https://github.com/jaydenseric/apollo-upload-server/blob/18ecdbc7a1f8b69ad51b4affbd986400033303d4/test.js#L39-L42
          if (error.code !== 'EPIPE') throw error;
        }

        service.close();
      });
开发者ID:simonjoom,项目名称:react-native-project,代码行数:80,代码来源:ApolloServer.test.ts


示例6: async

// Json sample

export const jsonHandler: RequestHandler = async (req, res) => {
    const data = await json(req);
    console.log(data);

    return 'Data logged to your console';
};

// socket.io chat app sample

const html = '<div>some html stuff</div>';

const server = micro(async (req, res) => {
    console.log('Serving index.html');
    res.end(html);
});

const io = socketIO(server);

server.listen(4000);

// Micro expects a function to be exported
module.exports = () => console.log('YOLO');

// body parsing sample

const bodyParsingHandler: RequestHandler = async (req, res) => {
    const buf = await buffer(req);
    console.log(buf);
    // <Buffer 7b 22 70 72 69 63 65 22 3a 20 39 2e 39 39 7d>
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:micro-tests.ts


示例7: handle

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


示例8: require

import cors = require('micro-cors');
import micro from 'micro';

const handler = cors();

cors({ allowMethods: ['PUT', 'POST'] });

cors({
    maxAge: '1000',
    origin: '*',
    allowHeaders: [],
    allowMethods: [],
    exposeHeaders: []
});

handler(async (req, res) => {});
handler((req, res) => {});
micro(handler((req, res) => {}));
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:18,代码来源:micro-cors-tests.ts


示例9: createApp

function createApp(options: CreateAppOptions = {}) {
  const server = new ApolloServer(
    (options.graphqlOptions as Config) || { schema: Schema },
  );
  return micro(server.createHandler());
}
开发者ID:apollostack,项目名称:apollo-server,代码行数:6,代码来源:microApollo.test.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript micro.json函数代码示例发布时间:2022-05-25
下一篇:
TypeScript index.MetricsCollector类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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