Skip to content

Commit

Permalink
added ngrok script, updated npm scripts and docker
Browse files Browse the repository at this point in the history
  • Loading branch information
pan261 committed Jan 28, 2022
1 parent 5da1780 commit 864e6a9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:16
WORKDIR /ffs/
COPY package.json ./
RUN npm install
RUN npm install --only=prod
COPY /src/build ./
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"version": "1.0.0",
"main": "/src/server.js",
"scripts": {
"start": "docker-compose up",
"start:docker": "docker-compose up",
"start:ngrok": "ngrok http 3000",
"test": "echo \"Error: no test specified\" && exit 1",
"tsc": "tsc",
"build": "tsc --build && docker-compose up --build --remove-orphans"
"build": "npm run open:page && npm run build:docker",
"build:docker": "node src/ngrok_script.js && tsc --build && docker-compose up --build --remove-orphans",
"open:page": "opener http://localhost:3000/auth"
},
"repository": {
"type": "git",
Expand All @@ -32,6 +34,7 @@
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.1",
"opener": "^1.5.2",
"typescript": "^4.5.2"
}
}
25 changes: 25 additions & 0 deletions src/ngrok_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const axios = require('axios');
const fs = require('fs');

axios({
method: 'GET',
url: 'http://127.0.0.1:4040/api/tunnels'
}).then(res => {
return res.data.tunnels;
}).then(data => {
data.forEach((entry) => {
if (entry.name === 'command_line (http)') {
const data = fs.readFileSync(`${__dirname}/../.env`).toString();
if (data.includes(entry.public_url)) {
console.log("ngrok callback url not changed");
return;
}
const newData = data.replace(new RegExp(/http:\/\/.+\.ngrok\.io/g), entry.public_url);
fs.writeFileSync(`${__dirname}/../.env`, newData);
console.log("updated ngrok callback url");
}
})
}).catch(err => {
console.log();
throw("ngrok server not started");
});

0 comments on commit 864e6a9

Please sign in to comment.