This is a Next.js E-commerce project bootstrapped with create-next-app
.
Navigate to project root folder through a CLI and run below commands one-by-one
brew install mkcert
mkcert -install
mkcert localhost
- Run below command in
Terminal
to openhosts
file.
sudo nano /etc/hosts # Enter computer password when asked
- Add below line at the end of the
hosts
file
127.0.0.1 ecommerce.local
- Save file and exit.
01. CTRL + O and Enter
02. CTRL + X
Now our local domain is (https://ecommerce.local)
- Create a file on
root folder
calledserver.js
- Put below code to the file
const { createServer } = require('https')
const { parse } = require('url')
const next = require('next')
const emoji = require('node-emoji')
const fs = require('fs')
const port = 3000
const dev = process.env.NODE_ENV !== 'production'
const hostname = 'localhost'
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()
const httpsOptions = {
key: fs.readFileSync(`./${hostname}-key.pem`),
cert: fs.readFileSync(`./${hostname}.pem`),
}
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}).listen(port, (err) => {
if (err) throw err
console.log(
'\x1b[32m',
`${emoji.get(
'popcorn'
)} Ready — started http(s) enabled server on url: https://${hostname}:${port}`
)
})
})
- Replace
"dev": "next dev",
with"dev": "node server.js",
inpackage.json
file. - Run
yarn dev
IMPORTANT: Make sure not to click "Yes" on making the opened browser as default browser as it'll replace your computers default chrome's data.
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security