A propriedade server
O Nuxt permite você definir as variáveis de conexão do servidor para a sua aplicação dentro do ficheiro nuxt.config.js
.
-
Tipo:
Object
Exemplo Básico:
export default {
server: {
port: 8000, // valor padrão: 3000
host: '0.0.0.0', // valor padrão: localhost,
timing: false
}
}
Isto permite você especificar o hospedeiro e a porta para a sua instância de servidor do Nuxt.
Exemplo usando a configuração do HTTPS
import path from 'path'
import fs from 'fs'
export default {
server: {
https: {
key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
}
}
}
Você pode encontrar informações adicionais sobre a criação de chaves e certificados de servidor no localhost
no artigo certificados para o localhost
.
Exemplo usando configuração do sockets
export default {
server: {
socket: '/tmp/nuxt.socket'
}
}
A propriedade timing
-
Tipo:
Object
ouBoolean
-
Valor padrão:
false
A ativação da opção server.timing
adiciona um intermediário para medir o tempo decorrido durante a renderização no lado do servidor e adiciona ele aos cabeçalhos como Server-Timing
Exemplo usando a configuração do timing
O server.timing
pode ser um objeto para fornecimento de opções. Atualmente, apenas o total
é suportado (o qual rastreia diretamente o tempo todo gasto na renderização do lado do servidor)
export default {
server: {
timing: {
total: true
}
}
}
Usando a API do timing
A API do timing
é também injetada dentro do response
no lado do servidor quando o server.time
estiver ativado.
A Sintaxe
res.timing.start(name, description)
res.timing.end(name)
Exemplo usando o timing dentro do serverMiddleware
export default function (req, res, next) {
res.timing.start('midd', 'Middleware timing description')
// operação no lado do servidor...
// ...
res.timing.end('midd')
next()
}
Depois o cabeçalho server-timing
será incluído dentro do cabeçalho de resposta como:
Server-Timing: midd;desc="Middleware timing description";dur=2.4
Recorra ao MDN do server-timing para mais detalhes.


















































