Last active
April 19, 2020 06:57
-
-
Save sp0033212000/8fe26081e38caa3c90a668cd24430722 to your computer and use it in GitHub Desktop.
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
const express = require("express"); | |
const path = require("path"); | |
const https = require("https"); | |
const fs = require("fs"); | |
const app = express(); | |
console.log(process.env.NODE_ENV); | |
if (process.env.NODE_ENV !== "production") { | |
const webpackMiddleware = require("webpack-dev-middleware"); | |
const webpackHotMiddleware = require("webpack-hot-middleware"); | |
const history = require("connect-history-api-fallback"); | |
const webpack = require("webpack"); | |
const webpackConfig = require("./webpack.config.dev"); | |
const compiler = webpack(webpackConfig); | |
// const staticFileMiddleware = express.static(path.join(__dirname)); | |
app.use( | |
webpackMiddleware(compiler, { | |
publicPath: webpackConfig.output.publicPath, | |
}) | |
); | |
app.use(webpackHotMiddleware(compiler)); | |
// app.use(staticFileMiddleware); | |
app.use( | |
history({ | |
verbose: true, | |
index: "/", | |
}) | |
); | |
// app.use(staticFileMiddleware); | |
// ^ `app.use(staticFileMiddleware)` is included twice as per https://github.com/bripkens/connect-history-api-fallback/blob/master/examples/static-files-and-index-rewrite/README.md#configuring-the-middleware | |
app.get("/", function (req, res) { | |
console.log(path.join(__dirname + "/public/index.html")); | |
res.sendFile(path.join(__dirname + "/public/index.html")); | |
}); | |
} else { | |
console.log("Prod Mode"); | |
app.use(express.static("bundle")); | |
app.get("*", (req, res) => { | |
res.sendFile(path.join(__dirname, "bundle/index.html")); | |
}); | |
} | |
https | |
.createServer( | |
{ | |
key: fs.readFileSync("./private/pillaAuth-key.pem"), | |
cert: fs.readFileSync("./private/pillaAuth-cert.pem"), | |
}, | |
app | |
) | |
.listen(process.env.PORT || 3000, () => { | |
console.log("Listening"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment