From 2a85305e3656e9fcc4a772b5e0bf30caff711e26 Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Mon, 25 Oct 2021 16:33:28 +0900 Subject: [PATCH] Local testing using HTTPS --- certs/localhost.crt | 18 ++++++++++++++++++ certs/localhost.key | 28 ++++++++++++++++++++++++++++ package.json | 3 ++- server.js | 20 ++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 certs/localhost.crt create mode 100644 certs/localhost.key create mode 100644 server.js diff --git a/certs/localhost.crt b/certs/localhost.crt new file mode 100644 index 0000000..7f069ec --- /dev/null +++ b/certs/localhost.crt @@ -0,0 +1,18 @@ +-----BEGIN CERTIFICATE----- +MIIC8DCCAdigAwIBAgIUKdikPQumOQj55w9ihJZB+PcxfEswDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIxMTAyNTA3MjgwNVoXDTIyMTAy +NTA3MjgwNVowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEA1lVmINtcbZLzPCW9IEgeSRjmW0e4EwQpZhs+rZPK4vTH +aouSFtAAtuSl8u5OIk03aRThc3/oAO3t+x1SsX9jua0MCi6IY1UGEJDRdaeq1uea +YnkG+Z5u0pt52eTbtYItAbKuMdn6rNOT4CTdZ10eTy/0mXHILTmbhPxOjPxflqIm +vjTyA5lMrAhTkFTc+Urpf8yw4pmxEHSLikuzZIkZ91hCwk7M+1fWZiVT/ed96m6C +aLyYePozpMM79zonv5+h7AS2Zu5FroEVLE5fKcHtBmiesVj3whbRgabOZWOyLWsD +SSttcrd/HPT+frwuf+TeV3ssVuGSfKNAcmgY3CajfQIDAQABozowODAUBgNVHREE +DTALgglsb2NhbGhvc3QwCwYDVR0PBAQDAgeAMBMGA1UdJQQMMAoGCCsGAQUFBwMB +MA0GCSqGSIb3DQEBCwUAA4IBAQCRmIA2AXilxqGdRxMbr25mEYu30MK1nUAyVbfo +Gdr8y03hbtLO29bseKO31zkXxlZeEnsd21P0n082HcsNRGt4tnkePhp7Ezw+5GYc +ecvvUMJq1XCKRsButIGa8KpGuA2V5nSpszOOYrJFC7bSIag+67ND7yOTPzr23rSV +ArSRKnNVlE1imu8Gz1V0ZrNbhb4tbWq6dXgNfQVphsENs+3kLe+X2976l47sKZ65 +4T4OqH6fzRXYDCQ9Syq8mRqb4rvwC1rHlAz/m7TATHlOGvFqU0pj+jI55Q1+dhLO +LYvegEbHFAGlmkKxkQR9dFxbpxP4xFYcf3GfyCZbsUZTo/VO +-----END CERTIFICATE----- diff --git a/certs/localhost.key b/certs/localhost.key new file mode 100644 index 0000000..3802958 --- /dev/null +++ b/certs/localhost.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDWVWYg21xtkvM8 +Jb0gSB5JGOZbR7gTBClmGz6tk8ri9Mdqi5IW0AC25KXy7k4iTTdpFOFzf+gA7e37 +HVKxf2O5rQwKLohjVQYQkNF1p6rW55pieQb5nm7Sm3nZ5Nu1gi0Bsq4x2fqs05Pg +JN1nXR5PL/SZccgtOZuE/E6M/F+Woia+NPIDmUysCFOQVNz5Sul/zLDimbEQdIuK +S7NkiRn3WELCTsz7V9ZmJVP9533qboJovJh4+jOkwzv3Oie/n6HsBLZm7kWugRUs +Tl8pwe0GaJ6xWPfCFtGBps5lY7ItawNJK21yt38c9P5+vC5/5N5XeyxW4ZJ8o0By +aBjcJqN9AgMBAAECggEBALbcwXeC8Aake1VztToXjY876T0zoT7ILDHrSLx6/XxI +7uJeFdPUvudLiLIM0yi8zGug3wDVvbEdTg8S43yAfSrrEvyU2tQ0tCnqBGrnFACq +NLOTInpRy6dv8rQOZ80iNRffxHLP0Okm0mFH0oXfkn5pIbzQsMK1BZSeVr4+i6dN +PNpMv+t/7+jkQSLV0UwSiMF3qHA4sslSBOcoQofW7NvhNgmmeKz2ok4sovp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package.json +++ b/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "start": "node server.js" }, "dependencies": { "next": "11.1.2", diff --git a/server.js b/server.js new file mode 100644 index 0000000..bd73d6e --- /dev/null +++ b/server.js @@ -0,0 +1,20 @@ +const { createServer } = require("https"); +const { parse } = require("url"); +const next = require("next"); +const fs = require("fs"); +const dev = process.env.NODE_ENV !== "production"; +const app = next({ dev }); +const handle = app.getRequestHandler(); +const httpsOptions = { + key: fs.readFileSync("./certs/localhost.key"), + cert: fs.readFileSync("./certs/localhost.crt"), +}; +app.prepare().then(() => { + createServer(httpsOptions, (req, res) => { + const parsedUrl = parse(req.url, true); + handle(req, res, parsedUrl); + }).listen(3000, (err) => { + if (err) throw err; + console.log("> Server started on https://localhost:3000"); + }); +}); \ No newline at end of file