Skip to content

Commit 614e759

Browse files
committed
Allow dev server and demo server to run on https
1 parent 4705fa7 commit 614e759

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

config.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
secret: process.env.LOOKER_EMBED_SECRET,
1313
demo_host: process.env.LOOKER_DEMO_HOST || 'localhost',
1414
demo_port: process.env.LOOKER_DEMO_PORT || 8080,
15+
demo_protocol: process.env.LOOKER_DEMO_PROTOCOL || 'http',
1516
client_id: process.env.LOOKER_CLIENT_ID,
1617
client_secret: process.env.LOOKER_CLIENT_SECRET,
1718
verify_ssl: process.env.LOOKER_VERIFY_SSL === 'true' || false,

server/app.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
2525
*/
2626

27+
import https from 'https'
28+
import fs from 'fs'
29+
import path from 'path'
2730
import express from 'express'
2831
import { addRoutes } from './routes'
2932
import { config } from './config'
@@ -37,6 +40,20 @@ addRoutes(app, config, user)
3740
app.use('/', express.static('public'))
3841

3942
const port = config.demo_port
40-
app.listen(port, () => {
41-
console.info(`Listening on port ${port}`)
42-
})
43+
44+
if (config.demo_protocol !== 'https') {
45+
app.listen(port, () => {
46+
console.info(`Listening on http://localhost:${port}`)
47+
})
48+
} else {
49+
const key = fs.readFileSync(path.join(__dirname, '/key.pem'))
50+
const cert = fs.readFileSync(path.join(__dirname, '/cert.pem'))
51+
const options = {
52+
cert: cert,
53+
key: key,
54+
}
55+
const server = https.createServer(options, app)
56+
server.listen(port, () => {
57+
console.info(`Listening on https://localhost:${port}`)
58+
})
59+
}

server/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const config: ApplicationConfig = {
4242
),
4343
demo_host: process.env.LOOKER_DEMO_HOST || 'localhost',
4444
demo_port: parseInt(process.env.LOOKER_DEMO_PORT || '8080', 10),
45+
demo_protocol: process.env.LOOKER_DEMO_PROTOCOL || 'http',
4546
host:
4647
process.env.LOOKER_WEB_URL ||
4748
process.env.LOOKER_EMBED_HOST || // deprecated

server/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface ApplicationConfig {
7575
client_secret: string
7676
demo_host: string
7777
demo_port: number
78+
demo_protocol: string
7879
host: string
7980
secret: string
8081
verify_ssl: boolean

webpack-devserver.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ var webpackConfig = {
5959
compress: true,
6060
host: config.demo_host,
6161
port: config.demo_port,
62+
server: config.demo_protocol,
63+
allowedHosts: 'all',
6264
app: () => {
6365
const app = express()
6466
addRoutes(app, config, user)

0 commit comments

Comments
 (0)