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


TypeScript micro.default函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。