mk95 Blog

website·Indexed 30 days ago

https://www.mk95.cn

A personal technical blog featuring guides and experiences with Nacos configuration, Vue.js iframe issues in IE, Tencent Cloud Code Assistant, EdgeOne static site hosting, and Podman mirror configuration.

Tokens
1.8K
Snippets
6
Records
12
Agent score
50%

What's inside mk95

  1. Explain complex code using Tencent Cloud Code Assistant

    Tencent Cloud Code Assistant helps developers understand and maintain code through the following features:

    • Detailed Explanations: Provides clear breakdowns of complex logic, explaining the execution process and purpose of the code.
    • Real-time Feedback: Offers immediate explanations and suggestions during the coding process to improve readability.
    • Knowledge Base Q&A: Includes a technical dialogue function to answer programming questions and resolve difficulties quickly.
  2. Perform AI-powered code reviews with Tencent Cloud Code Assistant

    Tencent Cloud Code Assistant provides automated code review capabilities to improve code quality and reduce manual effort. Key features include:

    • Intelligent Detection: Automatically identifies syntax and logic errors and suggests corrections to standardize code formatting.
    • Automated Review: Analyzes selected code snippets to identify potential bugs and performance bottlenecks.
    • Iterative Optimization: Supports multi-turn dialogues to refine diagnostic results and align them with developer expectations.
  3. Generate code using Tencent Cloud Code Assistant

    Tencent Cloud Code Assistant allows developers to automatically generate code based on specific requirements and comments. It supports multiple programming languages and frameworks, including HTML, JavaScript, Python, and Java. Additionally, it provides real-time intelligent code completion based on the current context to reduce syntax errors and typing time.
  4. Configure Podman to use a docker.io mirror registry

    To redirect Podman image pulls from the default Docker Hub registry to a specific mirror (e.g., docker.1panel.live), modify the registries configuration. This setup ensures that unqualified search requests for docker.io are routed to the specified mirror location and allows insecure connections if required.
    # Disable searching from multiple default registries and restrict to docker.io
    unqualified-search-registries = ["docker.io"]
    
    [[registry]]
    prefix = "docker.io"
    location = "docker.1panel.live"
    insecure = true
  5. Automate static site deployment from CNB to EdgeOne Pages

    To automate the build and deployment of a static site (e.g., Hexo) from a CNB repository to EdgeOne Pages, configure the .cnb.yml file. The pipeline should include a build stage to generate the static files and a deployment stage using the tencentcom/deploy-eopages image. The deployment command requires the directory of the generated files, the site name, and an EdgeOne secret token.
    push:
      eo_deploy:
        runner:
          cpus: 4
        docker:
          image: docker.cnb.cool/examples/workspace-images/workspace-node:22
        stages:
          - name: build
            script:
              - pnpm i
              - pnpm hexo generate
          - name: 部署我的 eo pages 正式环境
            imports:
              - https://cnb.cool/devsss/env/-/blob/main/tencent.yml
            image: tencentcom/deploy-eopages:latest
            script: edgeone pages deploy ./public -n cnb-www-devsss -t $EO_SECRET
  6. Configure a cloud development environment in CNB

    CNB provides a cloud-based development environment that persists configuration across sessions. You can set up a workspace for frameworks like Next.js, Hexo, or Docusaurus by defining the vscode section in .cnb.yml. This allows you to run a development server directly in the cloud environment.
    $:
      vscode:
        - docker:
            image: docker.cnb.cool/examples/workspace-images/workspace-node:22
          services:
            - vscode
            - docker
          stages:
            - name: 安装依赖
              script: pnpm i
            - name: 启动
              script: pnpm hexo server
  7. Configure Nacos Service Discovery and Config Center

    To integrate a Spring Boot application with Nacos, configure the server address, credentials, and namespace in bootstrap.yml. Additionally, define the application name and the specific Nacos configuration file to import in application.yml using the spring.config.import property with refresh=true to enable dynamic updates.
    # bootstrap.yml
    spring:
      cloud:
        nacos:
          discovery:
            server-addr: 192.168.1.4:8848
            username: nacos
            password: nacos
            namespace: public
            ip: 192.168.8.36
          config:
            server-addr: 192.168.1.4:8848
            username: nacos
            password: nacos
    
    # application.yml
    spring:
      application:
          name: app-test
      profiles:
        active: dev6
      config:
        import:
          - nacos:${spring.application.name}.yml?refresh=true
  8. Fix Nacos dynamic configuration not updating (Refresh keys changed: [])

    If you encounter the log message Refresh keys changed: [] after updating Nacos configurations and the values are not updating in the application, it is likely because the application failed to resolve spring.application.name during the bootstrap phase.

    This happens when the application name is defined in application.yml but the Nacos config import is processed too early. To resolve this, move the application name and Nacos import configuration from application.yml to bootstrap.yml to ensure they are loaded during the program's bootstrap phase.

  9. Understand Spring Cloud Config file loading order

    Spring Cloud Config loads configuration files in the following specific order of precedence (from earliest/lowest priority to latest/highest priority):

    1. bootstrap.yml (System-level parameters, loaded during program bootstrap)
    2. application.yml (Application-level common parameters)
    3. application-{profile}.yml (Profile-specific parameters)
    4. Configuration Center (Remote configurations from Nacos/Config Server)
  10. Fix blank iframe pages in IE for Vue apps using Hash mode

    When using Vue Router in hash mode, URLs starting with #/ are automatically redirected to index.html#/ in most browsers. However, Internet Explorer (IE) does not perform this redirection automatically within an iframe, resulting in a blank page. To resolve this, ensure the iframe source uses the full path including index.html instead of just the hash root.
    // Replace '/#/' with '/index.html#/' to ensure IE loads the page
    targetUrl = targetUrl.replaceAll("/#/", "/index.html#/");
  11. Force iframe refresh in Vue when changing source URL

    Vue may not automatically refresh an iframe when the src attribute changes. To force the iframe to reload when the URL is updated, bind a unique :key (such as a timestamp) to the iframe element. When the key changes, Vue will destroy and re-create the iframe component, triggering a fresh load of the new URL.
    <template>
      <div class="iframe-container">
        <iframe
          width="100%"
          height="100%"
          frameborder="0"
          :src="formattedUrl"
          :key="key"
        ></iframe>
      </div>
    </template>
    
    <script>
    export default {
      props: ["url"],
      data() {
        return {
          key: Date.now()
        }
      },
      computed: {
        formattedUrl() {
          let targetUrl = this.url;
          // Fix for IE blank page in Vue Hash mode
          targetUrl = targetUrl.replaceAll("/#/", "/index.html#/");
          // Update key to force iframe refresh
          this.key = Date.now();
          return targetUrl;
        },
      },
    };
    </script>
    
    <style>
    .iframe-container {
      height: 100%;
      overflow: hidden;
    }
    iframe {
      height: 100%;
      width: 100%;
    }
    </style>