1.10.18.6. fejezet, Node-Fetch SSL

Mintakód NextJS get kérésre

import { NextResponse } from "next/server";
import fetch from "node-fetch";
import fs from 'fs';
import path from "path";
import https from 'https';
 
export async function GET() {
    const options = {
        cert: fs.readFileSync(
            path.resolve('client.crt'),
            `utf-8`,
        ),
        key: fs.readFileSync(
            path.resolve('client.key'),
            'utf-8',
        ),
        rejectUnauthorized: false,
        keepAlive: true,
    }
 
    const sslConfiguredAgent = new https.Agent(options);
 
    try {
        const response = await fetch('https://localhost:8443/api/v2/tenant', {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json',
            },
            agent: sslConfiguredAgent,
        });
        const data = await response.json();
        return NextResponse.json(data);
    } catch (error) {
        return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
    }
}

Kapcsolódás a HTTPS szerverre