美文网首页
Hapi Example with skyapm

Hapi Example with skyapm

作者: AsaGuo | 来源:发表于2020-05-10 15:49 被阅读0次
// 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

      本文链接:https://www.haomeiwen.com/subject/qnujnhtx.html