大家好!
我有关于 Shopify 应用部署的问题(remix 模板)
我知道我可以将其部署在 Heroku 和 Fly.io。
从我在文档中读到的内容来看,可以将其部署在其他托管服务中。
所以,现在我正在尝试将其部署在Cloudways中。但现在的问题是,由于某种原因,它正在尝试访问 Cloudways 中的默认
index.php
文件。
应用程序的其他部分的工作方式如下:
example.com/auth/login
它有效!example.com/auth/callback
它有效!example.com/
不起作用☹️这就是为什么我觉得很奇怪,为什么当应用程序本身只是一个调用
build/index.js
的快速应用程序时它不起作用。我检查了我的 pm2
日志,每当我尝试访问该网站时,它都会抛出一个错误,提及 Error: No route matches URL "/index.php"
。
请注意,当我在 Cloudways 中创建应用程序时,
index.php
已经存在。
有关更多信息,这里有一些代码片段:
server.mjs
import { createRequestHandler } from "@remix-run/express";
import express from "express";
// notice that the result of `remix build` is "just a module"
import * as build from "./build/index.js";
// port is 4007
const port = process.env.PORT || 4007;
const app = express();
app.use(express.static("public"));
// and your app is "just a request handler"
app.all("*", createRequestHandler({ build }));
app.listen(port, () => {
console.log(`App listening on http://localhost:${port}`);
});
.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)?$ http://localhost:4007/$1 [P,L]
如果你们能告诉我我错过了什么,我将不胜感激?我真的不能在 Cloudways 中部署我的应用程序吗?
我尝试联系 Cloudways 支持,他们提到:
我们有一个自定义堆栈,因此它不支持某些应用程序类型,例如基于Python的框架在Ruby on Rails上工作,Shopify也是如此,因此它不能按自定义工作,但是,您可以做一件事,即启动直接服务器在我们的母公司 DigitalOcean 上,您可以使用这个自定义应用程序。
部署到其他托管服务对我来说不是一个选择,因为这对我来说并不具有成本效益。
如果真的不可能,有什么建议可以解决这个问题吗?
我已经找到了解决方案。对于任何尝试部署 Shopify Remix 应用程序的人,你们可以执行以下操作:
只需将
DirectoryIndex disabled
添加到您的 .htaccess
文件中。这应该可以防止它尝试访问默认的 index.php
文件。
DirectoryIndex disabled
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)?$ http://localhost:4007/$1 [P,L]
如果你们有比这更好的解决方案,请随时发布在这里。