Use certs to serve https
This commit is contained in:
parent
6d03f32009
commit
246debe642
@ -1,12 +1,18 @@
|
||||
import Fastify from 'fastify';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { app } from './app/app';
|
||||
|
||||
const host = process.env.HOST ?? 'localhost';
|
||||
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
|
||||
const host = process.env.API_HOST ?? 'localhost';
|
||||
const port = process.env.API_PORT ? Number(process.env.API_PORT) : 3000;
|
||||
|
||||
// Instantiate Fastify with some config
|
||||
const server = Fastify({
|
||||
logger: true,
|
||||
https: {
|
||||
key: fs.readFileSync(path.join(__dirname, '..', 'certs', 'key.pem')),
|
||||
cert: fs.readFileSync(path.join(__dirname, '..', 'certs', 'cert.pem')),
|
||||
}
|
||||
});
|
||||
|
||||
// Register your application as a normal plugin.
|
||||
@ -18,6 +24,6 @@ server.listen({ port, host }, (err) => {
|
||||
server.log.error(err);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(`[ ready ] http://${host}:${port}`);
|
||||
console.log(`[ ready ] https://${host}:${port}`);
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user