Commit 132c9250 authored by xiaodong.li's avatar xiaodong.li

init: 初始化项目

parents
Pipeline #228 failed with stages
node_modules
.vscode
# 使用文档
## 重启海外生产环境
```shell
$ npm run hw:start:oversea-prod:geoip
```
\ No newline at end of file
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const port = process.env.PORT;
console.log(`${process.env.name} is running on port:${port}`);
app.set('port', port);
app.use(bodyParser.json());
const router = require('./app/router/index');
app.use(router);
process.on('uncaughtException', function (err) {
console.error('error :', err);
});
process.on('unhandledRejection', (err) => {
console.error('unhandledRejection ', err);
});
// 启用数据观察器 文件更新时自动刷新内存数据
const geoip = require('geoip-lite');
geoip.startWatchingDataUpdate();
app.listen(port,()=>{
console.log('server listen on:',port);
});
\ No newline at end of file
const apis = require("geojson-places");
async function getLocationInfoFromGps(req,res){
const lat = parseFloat(req.body.lat);
const lon = parseFloat(req.body.lon);
const locationInfo = apis.lookUp(lat,lon);
console.log(`gps location ${lat,lon} ${JSON.stringify(locationInfo)}`);
return res.status(200).json(locationInfo || {});
}
module.exports = {
getLocationInfoFromGps,
}
\ No newline at end of file
const geoip = require('geoip-lite');
async function getLocationInfoByIp(req, res){
const ip = req.body.ip;
const locationInfo = geoip.lookup(ip);
console.log(`ip=${ip} location=${JSON.stringify(locationInfo)}`);
return res.status(200).json(locationInfo);
}
module.exports = {
getLocationInfoByIp,
}
\ No newline at end of file
const express = require('express');
const router = express.Router();
const ipController = require('../controller/ip');
// const gpsController = require('../controller/gps');
// 根据ip地址换取位置信息
router.post('/geoip/lookup',ipController.getLocationInfoByIp);
// 根据经纬度换取位置信息
// router.post('/gps/getLocationInfoFromGps',gpsController.getLocationInfoFromGps);
module.exports = router;
\ No newline at end of file
const env = process.argv[process.argv.indexOf('--env') + 1];
// 国内时区
const Shanghai_TZ = 'Asia/Shanghai';
// 雅加达时区
const Jakarta_TZ = 'Asia/Jakarta';
module.exports = {
"apps": [
{
"name": `${env}-ppfun-geoip`,
"script": "app.js",
"instances": 1,
"exec_mode": "fork",
'error_file': `/data/logs/server-ppfun/${env}-ppfun-geoip-error.log`,
'out_file': `/data/logs/server-ppfun/${env}-ppfun-geoip-out.log`,
'log_file': `/data/logs/server-ppfun/${env}-ppfun-geoip-error.log`,
"combine_logs": false,
"log_date_format": "YYYY-MM-DD HH:mm:ss.SSS ZZ",
'env_overseas-dev': {
"PORT": 7801,
'TZ': Jakarta_TZ,
},
'env_overseas-prod': {
"PORT": 7801,
'TZ': Jakarta_TZ,
}
}
]
}
\ No newline at end of file
{
"name": "server-ppfun-geoip",
"version": "1.0.0",
"description": "根据 IP 获取地区信息",
"private": true,
"scripts": {
"reload-geoip-data": "cd node_modules/geoip-lite && npm run-script updatedb license_key=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",
"hw:mkdir:overseas-dev": "ssh -tt node@101.44.161.199 'sudo mkdir -p /data/work/server-ppfun-overseas-dev/server-geoip && sudo chown node:root /data/work/server-ppfun-overseas-dev/server-geoip && sudo chmod 755 /data/work/server-ppfun-overseas-dev/server-geoip && sudo mkdir -p /data/logs/server-ppfun && sudo chown node:root /data/logs/server-ppfun && sudo chmod 755 /data/logs/server-ppfun'",
"hw:overseas-dev:sync-server": "rsync -avcrzl --delete-after . --exclude node_modules -e 'ssh' node@101.44.161.199:/data/work/server-ppfun-overseas-dev/server-geoip",
"hw:pm2:start:oversea-dev:geoip": "ssh -tt node@101.44.161.199 'cd /data/work/server-ppfun-overseas-dev/server-geoip && nvm use 16.20.2 && pm2 startOrGracefulReload ecosystem.config.js --env overseas-dev --update-env --only overseas-dev-ppfun-geoip'",
"hw:start:oversea-dev:geoip": "npm run hw:mkdir:overseas-dev && npm run hw:overseas-dev:sync-server && npm run hw:pm2:start:oversea-dev:geoip",
"hw:mkdir:overseas-prod": "ssh -tt node@49.0.200.160 'sudo mkdir -p /data/work/server-ppfun-overseas-prod/server-geoip && sudo chown node:root /data/work/server-ppfun-overseas-prod/server-geoip && sudo chmod 755 /data/work/server-ppfun-overseas-prod/server-geoip && sudo mkdir -p /data/logs/server-ppfun && sudo chown node:root /data/logs/server-ppfun && sudo chmod 755 /data/logs/server-ppfun'",
"hw:overseas-prod:sync-server": "rsync -avcrzl --delete-after . --exclude node_modules -e 'ssh' node@49.0.200.160:/data/work/server-ppfun-overseas-prod/server-geoip",
"hw:pm2:start:oversea-prod:geoip": "ssh -tt node@49.0.200.160 'cd /data/work/server-ppfun-overseas-prod/server-geoip && pm2 startOrGracefulReload ecosystem.config.js --env overseas-prod --update-env --only overseas-prod-ppfun-geoip'",
"hw:start:oversea-prod:geoip": "npm run hw:mkdir:overseas-prod && npm run hw:overseas-prod:sync-server && npm run hw:pm2:start:oversea-prod:geoip"
},
"author": "xiaodong.li",
"dependencies": {
"express": "^4.19.2",
"geoip-lite": "^1.4.10",
"geojson-places": "^1.0.8"
},
"main": "app.js",
"devDependencies": {},
"keywords": [
"server-ppfun"
],
"license": "ISC"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment