使用NextJS托管Apple验证文件

我正在使用NextJS。

根据here,我需要在应用程序上托管文件。

具体来说,它需要托管在:

https://app.blah.com/.well-known/apple-developer-merchantid-domain-association

从该文件夹提供此文件的最佳方法是什么?该网址必须与上述网址完全相同。

当我尝试将其放在顶层.well-known的文件夹中时,它不起作用。我怀疑是因为在实际构建应用程序时未提供该服务。

相反,如果我将文件放在其中,localhost/static/apple-developer-merchantid-domain-association可以正常工作。

那么,我该怎么办?

xutuzi 回答:使用NextJS托管Apple验证文件

Next.js public 文件夹中的任何内容都可以在根目录下访问。因此,将文件放在 /public/.well-known/apple-developer-merchantid-domain-association 中,即可在 yourdomain.com/.well-known/apple-developer-merchantid-domain-association 处访问。

,

解决方案:使用自定义服务器并按以下方式提供服务:

const express = require(`express`);
const next = require(`next`);
const path = require(`path`);
const compression = require(`compression`);

const env = require(`./config/environment`);

const { PORT } = env;

// On GAE,we want to use their port. Locally,we want to use our port.
const port = process.env.PORT || PORT;

const app = next({ dev: process.env.NODE_ENV !== `production` });
const handle = app.getRequestHandler();

const robotsOptions = {
  root: path.join(__dirname,`/static/`),headers: {
    "Content-Type": `text/plain;charset=UTF-8`,},};

const faviconOptions = {
  root: path.join(__dirname,};

const appleVerification = {
  root: path.join(__dirname,};

app.prepare().then(() => {
  const server = express();
  server.use(compression());

  server.get(`/robots.txt`,(req,res) => {
    res.status(200).sendFile(`robots.txt`,robotsOptions);
  });

  server.get(`/favicon.ico`,res) => res.status(200).sendFile(`favicon.ico`,faviconOptions));

  server.get(
    `/.well-known/apple-developer-merchantid-domain-association`,res) => res.status(200)
      .sendFile(
        `apple-developer-merchantid-domain-association`,appleVerification,),);

  server.get(`*`,res) => handle(req,res));

  server.listen(port,(err) => {
    if (err) {
      throw err;
    }
    console.log(`Server running on port: ${port}.`);
  });
});

本文链接:https://www.f2er.com/3121899.html

大家都在问