-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (42 loc) · 1.08 KB
/
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
43
44
45
46
47
48
import { createRequestHandler } from "@remix-run/express";
import express from "express";
import {createIPX, createIPXNodeServer, ipxFSStorage, ipxHttpStorage } from "ipx";
import 'dotenv/config'
const ipx = createIPX({
storage: ipxFSStorage({ dir: "./public"}),
httpStorage: ipxHttpStorage({ domains: [process.env.STRAPI_URL] }),
alias: {
strapi: process.env.STRAPI_URL,
},
});
const viteDevServer =
process.env.NODE_ENV === "production"
? null
: await import("vite").then((vite) =>
vite.createServer({
server: { middlewareMode: true },
})
);
const app = express();
app.use(
viteDevServer
? viteDevServer.middlewares
: express.static("build/client")
);
app.use(
"/_ipx",
(req, res, next) => {
next();
},
createIPXNodeServer(ipx)
);
const build = viteDevServer
? () =>
viteDevServer.ssrLoadModule(
"virtual:remix/server-build"
)
: await import("./build/server/index.js");
app.all("*", createRequestHandler({ build }));
app.listen(3000, () => {
console.log("App listening on http://localhost:3000");
});