Hapi Example with skyapm

// main.js
// 在引入所有模块之前,启动skyapm-nodejs代理
require('skyapm-nodejs').start({
    serviceName: 'terminalapi2',
    directServers: '127.0.0.1:11800'
});

const Hapi = require('@hapi/hapi')
const userRoutes = require('./routes/users')
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || '7000';

(async () => {
    const server = Hapi.server({
        host: HOST,
        port: PORT,

        // define route defaults
        routes: {
            // enable CORS
            cors: true,
            validate: {
                failAction: async (request, h, err) => {
                    throw Boom.badRequest(err.message);
                }
            }
        }
    })

    // definition of the base route
    server.route({
        method: 'GET',
        path: '/',
        handler: (request, h) => {
            // respond with a json object
            return h.response({ message: 'Asa is a super man!' })
        }
    })
    await server.register(userRoutes);
    server.start();
    console.info(`Server started at:${server.info.uri}`)
})();

你可能感兴趣的:(Hapi Example with skyapm)