將引數傳遞給路徑

可以在路由配置的 path 屬性中指定引數

'use strict';

const Hapi = require('hapi');

// Create a server with a host and port
const server = new Hapi.Server();

server.connection({ 
    host: 'localhost', 
    port: 8000 
});

// Add a route path with url param
server.route({
    method: 'GET',
    path:'/hello/{name}', 
    handler: function (request, reply) {
        // Passed parameter is accessible via "request.params" 
        return reply(`Hello ${request.params.name}`);
    }
});

// Start the server
server.start((err) => {
    if (err) {
        throw err;
    }
    console.log('Server running at:', server.info.uri);
});