From 353a58eb1ba22368c0a804693f08b814d18e8970 Mon Sep 17 00:00:00 2001 From: willwill96 Date: Mon, 18 May 2020 16:18:36 -0600 Subject: [PATCH] Add Https to nextjs --- app/package.json | 5 ++++- app/src/server.js | 23 +++++++++++++++++++++++ app/yarn.lock | 5 +++++ graphql/src/configuration.tsx | 2 +- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 app/src/server.js diff --git a/app/package.json b/app/package.json index 9f23b1e4..c2de3e34 100644 --- a/app/package.json +++ b/app/package.json @@ -11,7 +11,8 @@ "lint": "eslint .", "test:prettier": "prettier --check \"**/*.{js,jsx,ts,tsx,json}\"", "test:mocha": "cross-env NODE_ENV=test mocha", - "test": "yarn test:prettier && yarn lint && yarn test:mocha && yarn build" + "test": "yarn test:prettier && yarn lint && yarn test:mocha && yarn build", + "start:new": "node src/server.js" }, "dependencies": { "@apollo/react-hooks": "3.1.3", @@ -33,6 +34,7 @@ "golden-layout": "^1.5.9", "graphql": "^14.0.2", "graphql-tag": "2.10.3", + "https": "^1.0.0", "immutable": "^4.0.0-rc.12", "isomorphic-unfetch": "^3.0.0", "lodash.throttle": "^4.1.1", @@ -48,6 +50,7 @@ "react-beautiful-dnd": "^13.0.0", "react-dom": "^16.7.0", "universal-cookie": "^4.0.3", + "url": "^0.11.0", "uuid": "^7.0.3" }, "license": "ISC", diff --git a/app/src/server.js b/app/src/server.js new file mode 100644 index 00000000..8a56642c --- /dev/null +++ b/app/src/server.js @@ -0,0 +1,23 @@ +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() +// @ts-ignore +process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0 +const httpsOptions = { + key: fs.readFileSync('../server.key'), + cert: fs.readFileSync('../server.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('> Ready on https://localhost:3000') + }) +}) diff --git a/app/yarn.lock b/app/yarn.lock index d686e803..ab6ac619 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -7810,6 +7810,11 @@ https-browserify@^1.0.0: resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73" integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM= +https@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/https/-/https-1.0.0.tgz#3c37c7ae1a8eeb966904a2ad1e975a194b7ed3a4" + integrity sha1-PDfHrhqO65ZpBKKtHpdaGUt+06Q= + hyphenate-style-name@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/hyphenate-style-name/-/hyphenate-style-name-1.0.3.tgz#097bb7fa0b8f1a9cf0bd5c734cf95899981a9b48" diff --git a/graphql/src/configuration.tsx b/graphql/src/configuration.tsx index c5677f32..89bf85f7 100644 --- a/graphql/src/configuration.tsx +++ b/graphql/src/configuration.tsx @@ -1,6 +1,6 @@ import url from 'url' const defaultDdfUrl = 'https://localhost:8993' -const defaultWebappUrl = 'http://localhost:3000' +const defaultWebappUrl = 'https://localhost:3000' const parsableAttributes: Record = { FETCH_ORIGIN: () => process.env['FETCH_ORIGIN'] && url.parse(process.env['FETCH_ORIGIN']),