-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
32 lines (25 loc) · 998 Bytes
/
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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const express = require('express');
const compression = require('compression');
const scProxy = require('@sitecore-jss/sitecore-jss-proxy').default;
const config = require('./config');
const server = express();
const port = process.env.PORT || 3000;
// enable gzip compression for appropriate file types
server.use(compression());
// turn off x-powered-by http header
server.settings['x-powered-by'] = false;
// Serve static app assets from local /dist folder
server.use(
'/dist/hello-jss-typescript/',
express.static('../hello-jss-typescript/build', {
fallthrough: false, // force 404 for unknown assets under /disthello-jss-typescript/
})
);
// For any other requests, we render app routes server-side and return them
server.use('*', scProxy(config.serverBundle.renderView, config, config.serverBundle.parseRouteUrl));
server.listen(port, () => {
console.log(`server listening on port ${port}!`);
});