Skip to content

Commit

Permalink
Stub app for SPA hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
f213 committed Apr 12, 2022
0 parents commit d24910b
Show file tree
Hide file tree
Showing 4 changed files with 1,330 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const express = require("express");
const morgan = require("morgan");
const consola = require("consola");
const history = require('connect-history-api-fallback');
const { createProxyMiddleware } = require("http-proxy-middleware");

const app = express();

app.set("trust proxy", "loopback");
app.use(morgan("combined"));

app.use("/healthcheck/", (_, res) => res.send("OK"));

const target = process.env.BACKEND_URL || "https://app.tough-dev.school";

app.use(
["/admin", "/api", "/static"],
createProxyMiddleware({
target,
changeOrigin: Boolean(target.includes("https")),
})
);

const staticFolder = process.env.STATIC_FOLDER || '/dist';

consola.info(`Serving static from ${staticFolder}`);
app.use(history());
app.use(express.static(staticFolder))

/* Run express */
const host = process.env.HOST || '0.0.0.0';
const port = process.env.PORT || 3000;
app.set('port', port);
app.listen(port, host);

consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true,
});
Loading

0 comments on commit d24910b

Please sign in to comment.