如何在没有域 (.com) 的 localhost/Ip 地址上为应用程序 运行 创建 CDN

How to create a CDN for an application running on localhost/Ip address without a domain (.com)

为了提高应用程序的性能,我想在 CDN 上托管我的静态资产。但是我们还没有使用 nginx 创建域。如何仍然使用像这样的 cdn - express-simple-cdn link -

https://www.keycdn.com/support/express-cdn-integration

我需要在我的 Angular 应用程序的 app.js 文件中写这个 domainName.com,我通过它托管我的应用程序--

// Initialize Express in a variable in app.js
var app = express();

// Define Your CDN base path
var CDN = "https://assets.preisheld.ch";
// Register a local variable in your app which contains the CDN function
app.locals.CDN = function(path, type, classes, alt) {
    if(type == 'js') {
        return "<script src='"+CDN+path+"' type='text/javascript'></script>";
    } else if (type == 'css') {
        return "<link rel='stylesheet' type='text/css' href='"+CDN+path+"'/>";
    } else if (type == 'img') {
        return "<img class='"+classes+"' src='"+CDN+path+"' alt='"+alt+"' />";
    } else {
        return "";
    }
};

在这种情况下如何利用CDN?

So is there a dummy a place where you can create your domainName.com address for free while opening it in your local ip address

是的!那是 hosts 文件。您可以在您的系统上找到它:

  • Windows: C:\Windows\System32\Drivers\etc\hosts
  • Linux: /etc/hosts
  • OS X: /private/etc/hosts

此文件允许您将任意主机名映射到网络地址,覆盖来自 DNS 的任何内容。例如:

127.0.0.1 yourproject.test

现在,如果您在浏览器中转到 http://yourproject.test,它将解析为 127.0.0.1 并在您的环回地址上连接 Web 服务器 运行。如果您使用的是 IPv6,use ::1 instead of 127.0.0.1.

您可以设置任何您想要的主机名...甚至是真实存在的主机名。但是,强烈建议您使用 .test 顶级域,因为它专门保留用于测试目的。