Sử dụng ngrok cho dự án từ localhost ra ngoài internet - quan1997ap/angular-app-note GitHub Wiki

https://kb.pavietnam.vn/ngrok-su-dung-ngrok-cho-du-an-tu-localhost-ra-ngoai-internet.html

1. install

https://ngrok.com/download

snap install ngrok

2. Add token

https://dashboard.ngrok.com/get-started/setup/linux

ngrok config add-authtoken <token>

3. Start app local

app.js

const express = require("express");
const app = express();
const port = 5000;
const bodyParser = require("body-parser");
app.use(bodyParser.json());
app.use(express.static("public"));

app.get("/", (req, res) => {
  const axios = require("axios");
  res.send("Hello World!");
});

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`);
});

let users = [{ name: "Alice" }, { name: "Bob" }];
app.get("/users", (req, res) => {
  res.json(users);
});

package.json

{
    "name": "webhook",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "start": "nodemon --inspect=0.0.0.0:9999 app.js"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
      "axios": "^1.7.2",
      "body-parser": "^1.20.2",
      "express": "^4.19.2"
    }
  }

Start app local

npm start

4. Public port

Mỗi lần chỉ public được 1 port

public app chạy ở port 5000
ngrok http 5000

public app chạy ở port 5000
ngrok http 80

5. Kết quả

image

Truy cập https://c3b0-118-70-184-62.ngrok-free.app để xem kết quả

⚠️ **GitHub.com Fallback** ⚠️