-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (33 loc) · 973 Bytes
/
server.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
// @ts-check
const fs = require('fs');
const bodyParser = require('body-parser');
const path = require('path');
const express = require('express');
const {hydrogenMiddleware} = require('@shopify/hydrogen/middleware');
const resolve = (p) => path.resolve(__dirname, p);
async function createServer() {
const indexProd = fs.readFileSync(resolve('dist/client/index.html'), 'utf-8');
const app = express();
app.use(require('compression')());
app.use(
require('serve-static')(resolve('dist/client'), {
index: false,
}),
);
app.use('*', bodyParser.raw({type: '*/*'}));
app.use(
'*',
hydrogenMiddleware({
getServerEntrypoint: () =>
require('./dist/server/entry-server.js').default,
indexTemplate: indexProd,
}),
);
return {app};
}
createServer().then(({app}) => {
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`Hydrogen running at http://localhost:${port}`);
});
});