-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (46 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @remix-run/serve v1.5.1
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var express = require('express');
var compression = require('compression');
var morgan = require('morgan');
var express$1 = require('@remix-run/express');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
var compression__default = /*#__PURE__*/_interopDefaultLegacy(compression);
var morgan__default = /*#__PURE__*/_interopDefaultLegacy(morgan);
function createApp(buildPath, mode = "production") {
let app = express__default["default"]();
app.disable("x-powered-by");
app.use(compression__default["default"]());
app.use("/build", express__default["default"].static("public/build", {
immutable: true,
maxAge: "1y"
}));
app.use(express__default["default"].static("public", {
maxAge: "1h"
}));
app.use(morgan__default["default"]("tiny"));
app.all("*", mode === "production" ? express$1.createRequestHandler({
build: require(buildPath),
mode
}) : (req, res, next) => {
// require cache is purged in @remix-run/dev where the file watcher is
let build = require(buildPath);
return express$1.createRequestHandler({
build,
mode
})(req, res, next);
});
return app;
}
exports.createApp = createApp;