index.js 708 字节
Newer Older
J
Jason Park 已提交
1 2 3 4 5
const compression = require('compression');
const history = require('connect-history-api-fallback');
const express = require('express');
const app = express();

J
Jason Park 已提交
6 7 8
const frontend = require('./frontend');
const backend = require('./backend');

J
Jason Park 已提交
9
const {
J
Jason Park 已提交
10
  apiEndpoint,
J
Jason Park 已提交
11
  credentials,
J
Jason Park 已提交
12 13
} = require('../environment');

J
Jason Park 已提交
14
app.use((req, res, next) => {
J
Jason Park 已提交
15 16 17 18 19 20 21
  if (req.hostname === 'algo-visualizer.jasonpark.me') {
    res.redirect(301, 'https://algorithm-visualizer.org/');
  } else if (credentials && !req.secure) {
    res.redirect(301, `https://${req.hostname}${req.url}`);
  } else {
    next();
  }
J
Jason Park 已提交
22
});
23
app.use(apiEndpoint, backend);
J
Jason Park 已提交
24 25 26 27
app.use(history());
app.use(compression());
app.use(frontend);

J
Jason Park 已提交
28
module.exports = app;