Preview with https:// instead of http?

So the question is in the title - is it possible to run a https:// instead of plain http:// for a preview?
We use CC v3.7.3

The preview is running locally, and we don’t have any https certificate for local server

I can make my own certificate. With tools like mkcert it is easy to do nowadays.

Is there any way to use my own local server (e.g. serve) to serve the preview build? Where are the preview files are located?

Just point your web server with ssl to load files from build folder and view there.

I get how to do it with the build folder but what about preview build?

One that starts when from here

Preview build is using our internal node js server, it’s not related to any certificate, and we don’t plan to add any certificate. Why do you need https just for local preview ?

1 Like

I see. Cocos Creator does not have your requested feature readily available.
So, how about we setup a proxy server with ssl and intercept the preview URL and rewrite to https?

A good read:

1 Like

preview build ‘communicates’ with backend that is available only via https

thanks, I have ended up with this solution

const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
const { createProxyMiddleware } = require('http-proxy-middleware');

const HOST = 'localhost';
const PORT = 5050;
const TARGET_URL = 'https://server-develop.app';

const app = express();

// Logging
app.use(morgan('[:date[iso]] :method :url :status'));

app.use(cors());

// Proxy endpoints
app.use(
	'/',
	createProxyMiddleware({
		target: TARGET_URL,
		changeOrigin: true,
	})
);

app.listen(PORT, HOST, () => {
	console.log(`Proxy started at http://${HOST}:${PORT}`);
});
2 Likes