-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate restify to express for non-sso-tab (#12640)
- Loading branch information
Showing
4 changed files
with
59 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
const restify = require("restify"); | ||
const send = require("send"); | ||
const express = require("express"); | ||
const fs = require("fs"); | ||
const https = require("https"); | ||
const path = require("path"); | ||
const send = require("send"); | ||
|
||
//Create HTTP server. | ||
const server = restify.createServer({ | ||
key: process.env.SSL_KEY_FILE ? fs.readFileSync(process.env.SSL_KEY_FILE) : undefined, | ||
certificate: process.env.SSL_CRT_FILE ? fs.readFileSync(process.env.SSL_CRT_FILE) : undefined, | ||
formatters: { | ||
"text/html": function (req, res, body) { | ||
return body; | ||
}, | ||
}, | ||
}); | ||
const app = express(); | ||
|
||
server.get( | ||
"/static/*", | ||
restify.plugins.serveStatic({ | ||
directory: __dirname, | ||
}) | ||
); | ||
const sslOptions = { | ||
key: process.env.SSL_KEY_FILE ? fs.readFileSync(process.env.SSL_KEY_FILE) : undefined, | ||
cert: process.env.SSL_CRT_FILE ? fs.readFileSync(process.env.SSL_CRT_FILE) : undefined, | ||
}; | ||
|
||
server.listen(process.env.port || process.env.PORT || 3333, function () { | ||
console.log(`\n${server.name} listening to ${server.url}`); | ||
}); | ||
app.use("/static", express.static(path.join(__dirname, "static"))); | ||
|
||
// Adding tabs to our app. This will setup routes to various views | ||
// Setup home page | ||
server.get("/", (req, res, next) => { | ||
send(req, __dirname + "/views/hello.html").pipe(res); | ||
app.get("/", (req, res) => { | ||
send(req, path.join(__dirname, "views", "hello.html")).pipe(res); | ||
}); | ||
|
||
// Setup the static tab | ||
server.get("/tab", (req, res, next) => { | ||
send(req, __dirname + "/views/hello.html").pipe(res); | ||
app.get("/tab", (req, res) => { | ||
send(req, path.join(__dirname, "views", "hello.html")).pipe(res); | ||
}); | ||
|
||
// Create HTTP server | ||
const port = process.env.port || process.env.PORT || 3333; | ||
|
||
if (sslOptions.key && sslOptions.cert) { | ||
https.createServer(sslOptions, app).listen(port, () => { | ||
console.log(`Express server listening on port ${port}`); | ||
}); | ||
} else { | ||
app.listen(port, () => { | ||
console.log(`Express server listening on port ${port}`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
import * as restify from "restify"; | ||
import express from "express"; | ||
import * as fs from "fs"; | ||
import * as https from "https"; | ||
import * as path from "path"; | ||
import send from "send"; | ||
|
||
//Create HTTP server. | ||
const server = restify.createServer({ | ||
key: process.env.SSL_KEY_FILE ? fs.readFileSync(process.env.SSL_KEY_FILE) : undefined, | ||
certificate: process.env.SSL_CRT_FILE ? fs.readFileSync(process.env.SSL_CRT_FILE) : undefined, | ||
formatters: { | ||
"text/html": (req, res, body) => { | ||
return body; | ||
}, | ||
}, | ||
}); | ||
const app = express(); | ||
|
||
server.get( | ||
"/static/*", | ||
restify.plugins.serveStatic({ | ||
directory: __dirname, | ||
}) | ||
); | ||
const sslOptions = { | ||
key: process.env.SSL_KEY_FILE ? fs.readFileSync(process.env.SSL_KEY_FILE) : undefined, | ||
cert: process.env.SSL_CRT_FILE ? fs.readFileSync(process.env.SSL_CRT_FILE) : undefined, | ||
}; | ||
|
||
server.listen(process.env.port || process.env.PORT || 3333, function () { | ||
console.log(`\n${server.name} listening to ${server.url}`); | ||
}); | ||
app.use("/static", express.static(path.join(__dirname, "static"))); | ||
|
||
// Adding tabs to our app. This will setup routes to various views | ||
// Setup home page | ||
server.get("/", (req, res, next) => { | ||
send(req, __dirname + "/views/hello.html").pipe(res); | ||
app.get("/", (req, res) => { | ||
send(req, path.join(__dirname, "views", "hello.html")).pipe(res); | ||
}); | ||
|
||
// Setup the static tab | ||
server.get("/tab", (req, res, next) => { | ||
send(req, __dirname + "/views/hello.html").pipe(res); | ||
app.get("/tab", (req, res) => { | ||
send(req, path.join(__dirname, "views", "hello.html")).pipe(res); | ||
}); | ||
|
||
// Create HTTP server | ||
const port = process.env.port || process.env.PORT || 3333; | ||
|
||
if (sslOptions.key && sslOptions.cert) { | ||
https.createServer(sslOptions, app).listen(port, () => { | ||
console.log(`Express server listening on port ${port}`); | ||
}); | ||
} else { | ||
app.listen(port, () => { | ||
console.log(`Express server listening on port ${port}`); | ||
}); | ||
} |