Compare commits
No commits in common. 'master' and 'v1.0.0' have entirely different histories.
@ -1,31 +0,0 @@
|
|||||||
name: release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [master]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Setup Node.js environment
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
cache: 'npm'
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
- name: Build
|
|
||||||
run: npm run build
|
|
||||||
- name: Rename output dir
|
|
||||||
run: mv build sergate
|
|
||||||
- name: Make zip file
|
|
||||||
run: zip -r -9 sergate.zip ./sergate -x .gitignore
|
|
||||||
- name: Semantic release
|
|
||||||
run: npx semantic-release
|
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"branch": "master",
|
|
||||||
"ci": "true",
|
|
||||||
"plugins": [
|
|
||||||
"@semantic-release/commit-analyzer",
|
|
||||||
"@semantic-release/release-notes-generator",
|
|
||||||
[
|
|
||||||
"@semantic-release/changelog",
|
|
||||||
{
|
|
||||||
"changelogFile": "CHANGELOG.md"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@semantic-release/git",
|
|
||||||
{
|
|
||||||
"assets": [
|
|
||||||
"CHANGELOG.md"
|
|
||||||
],
|
|
||||||
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@semantic-release/github",
|
|
||||||
{
|
|
||||||
"assets": {
|
|
||||||
"path": "sergate.zip",
|
|
||||||
"name": "sergate-${nextRelease.version}.zip"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"publicConfig": "next"
|
|
||||||
}
|
|
||||||
@ -1,122 +0,0 @@
|
|||||||
## [2.0.3](https://github.com/krwu/ServerStatus-web/compare/v2.0.2...v2.0.3) (2023-03-07)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* http-cache-semantics vulnerable ([dac1abc](https://github.com/krwu/ServerStatus-web/commit/dac1abc1112c6a6388f691e7697bb0dc5fd93558))
|
|
||||||
|
|
||||||
## [2.0.2](https://github.com/krwu/ServerStatus-web/compare/v2.0.1...v2.0.2) (2022-09-13)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* **npm:** potential security vulnerabilities ([10db0cb](https://github.com/krwu/ServerStatus-web/commit/10db0cbb2d37d2be7a43e9279c2c60099237c1fa))
|
|
||||||
|
|
||||||
## [2.0.1](https://github.com/krwu/ServerStatus-web/compare/v2.0.0...v2.0.1) (2022-07-14)
|
|
||||||
|
|
||||||
|
|
||||||
### Performance Improvements
|
|
||||||
|
|
||||||
* clean unnecessary packages ([d5a1dd0](https://github.com/krwu/ServerStatus-web/commit/d5a1dd007cecafe7b4461e98667410ae099b6e3d))
|
|
||||||
|
|
||||||
# [2.0.0](https://github.com/krwu/ServerStatus-web/compare/v1.4.0...v2.0.0) (2022-06-14)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* upgrade dependencies ([eeff4c0](https://github.com/krwu/ServerStatus-web/commit/eeff4c0eaf59122bc984be4ab3970dbaf72164d1))
|
|
||||||
|
|
||||||
|
|
||||||
### BREAKING CHANGES
|
|
||||||
|
|
||||||
* - react-scripts upgraded to v5
|
|
||||||
- semantic-release upgraded to v19
|
|
||||||
- dropped support for Node <= 15
|
|
||||||
|
|
||||||
# [1.4.0](https://github.com/krwu/ServerStatus-web/compare/v1.3.0...v1.4.0) (2022-02-19)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* upgrade dependencies ([c9a4f11](https://github.com/krwu/ServerStatus-web/commit/c9a4f11286bd6d4788a78853af81104940b62fff))
|
|
||||||
|
|
||||||
# [1.3.0](https://github.com/krwu/ServerStatus-web/compare/v1.2.0...v1.3.0) (2021-09-22)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* bump antd version to 4.0 ([664003d](https://github.com/krwu/ServerStatus-web/commit/664003df1bf2d2f4eed04cc0334dcb22db0baa31))
|
|
||||||
|
|
||||||
# [1.2.0](https://github.com/krwu/ServerStatus-web/compare/v1.1.5...v1.2.0) (2021-09-22)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* ignore local registry ([15158f4](https://github.com/krwu/ServerStatus-web/commit/15158f4c8d1523f2d2983a5bbf164660113211be))
|
|
||||||
* serviceWorker cause building failed ([bc548af](https://github.com/krwu/ServerStatus-web/commit/bc548af585014c29f2621c98599d63c4955c83ee))
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* **ui:** add index for each row ([1c0fbfe](https://github.com/krwu/ServerStatus-web/commit/1c0fbfe86ea034d2bda0c32cc861bef52accac7d))
|
|
||||||
|
|
||||||
## [1.1.5](https://github.com/krwu/ServerStatus-web/compare/v1.1.4...v1.1.5) (2020-11-05)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* locale ('1 day' doesn't work), mobile style ('name' item size) ([cf5c3b6](https://github.com/krwu/ServerStatus-web/commit/cf5c3b6638400203f694d1776488057dfbf42e87))
|
|
||||||
|
|
||||||
## [1.1.4](https://github.com/krwu/ServerStatus-web/compare/v1.1.3...v1.1.4) (2020-05-05)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* display name with host or name from json ([a19256c](https://github.com/krwu/ServerStatus-web/commit/a19256c9e83345ec18916ce7620e57461228face)), closes [#2](https://github.com/krwu/ServerStatus-web/issues/2)
|
|
||||||
|
|
||||||
## [1.1.3](https://github.com/krwu/ServerStatus-web/compare/v1.1.2...v1.1.3) (2020-04-09)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* pull data once page loaded instead of wait 5m ([f244dec](https://github.com/krwu/ServerStatus-web/commit/f244decff163a847ee9da3999b352a33f554c15b))
|
|
||||||
|
|
||||||
## [1.1.2](https://github.com/krwu/ServerStatus-web/compare/v1.1.1...v1.1.2) (2020-02-04)
|
|
||||||
|
|
||||||
|
|
||||||
### Performance Improvements
|
|
||||||
|
|
||||||
* **data:** improve fetch interval from 2s to 5s ([4bd86e3](https://github.com/krwu/ServerStatus-web/commit/4bd86e3f7b18fd33054cbddeae185bc5cde6338e))
|
|
||||||
|
|
||||||
## [1.1.1](https://github.com/krwu/ServerStatus-web/compare/v1.1.0...v1.1.1) (2019-12-22)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* add missed locale entities ([88245b6](https://github.com/krwu/ServerStatus-web/commit/88245b68d90373870cd7b9b000c2dcb85af3fad0))
|
|
||||||
|
|
||||||
# [1.1.0](https://github.com/krwu/ServerStatus-web/compare/v1.0.1...v1.1.0) (2019-12-21)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* add international support ([5391fea](https://github.com/krwu/ServerStatus-web/commit/5391feab9f36d625293b70066cbb9838a7075ea5))
|
|
||||||
|
|
||||||
# Changelog
|
|
||||||
|
|
||||||
## [1.0.1](https://github.com/krwu/ServerStatus-web/compare/v1.0.0...v1.0.1) (2019-09-16)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* change footer link target ([f8f73d3](https://github.com/krwu/ServerStatus-web/commit/f8f73d3))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [1.0.0](https://github.com/krwu/ServerStatus-web/compare/9097c1b...v1.0.0) (2019-08-29)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* implement web ui development ([9097c1b](https://github.com/krwu/ServerStatus-web/commit/9097c1b))
|
|
||||||
* update footer ([467de09](https://github.com/krwu/ServerStatus-web/commit/467de09))
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
||||||
Version 2, December 2004
|
|
||||||
|
|
||||||
Copyright (C) 2019 Kairee Wu <kairee@udev.bid>
|
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim or modified
|
|
||||||
copies of this license document, and changing it is allowed as long
|
|
||||||
as the name is changed.
|
|
||||||
|
|
||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
|
||||||
@ -1,50 +0,0 @@
|
|||||||
# Web UI for ServerStatus
|
|
||||||
|
|
||||||
[English](README.md) | **简体中文**
|
|
||||||
|
|
||||||
本项目是为 [BotoX's ServerStatus](https://github.com/BotoX/ServerStatus/) 开发的前端展示界面.
|
|
||||||
|
|
||||||
[](https://travis-ci.com/krwu/ServerStatus-web)
|
|
||||||

|
|
||||||
[](https://github.com/krwu/ServerStatus-web/releases)
|
|
||||||
[](http://commitizen.github.io/cz-cli/)
|
|
||||||
[](https://github.com/krwu/ServerStatus-web/blob/master/COPYING.txt)
|
|
||||||

|
|
||||||
|
|
||||||
## 演示:
|
|
||||||
|
|
||||||
[https://udev.bid/sergate/](https://udev.bid/sergate/)
|
|
||||||
|
|
||||||
## 使用方法:
|
|
||||||
|
|
||||||
你必须首先成功安装和运行 [BotoX's ServerStatus](https://github.com/BotoX/ServerStatus/)。因为这个项目仅仅是一个可以即插即用的可替换的 web 界面。
|
|
||||||
|
|
||||||
### **使用预编译版:**
|
|
||||||
|
|
||||||
1. 从 [release 页面](https://github.com/krwu/ServerStatus-web/releases)下载最新的预编译压缩包。
|
|
||||||
2. 解压下载的文件。
|
|
||||||
3. 把 `sergate` 目录下的所有文件上传到你的 ServerStatus 的 web 目录(推荐操作:你可以先删除**原目录**下除了 `json/status.json` 以外的所有文件)。
|
|
||||||
|
|
||||||
### **自己编译:**
|
|
||||||
|
|
||||||
1. 你需要安装有 Node.js, npm 或者 yarn.
|
|
||||||
2. 克隆本项目,或者下载打包的源代码到你的机器。
|
|
||||||
3. 进入项目根目录(或解压后的文件夹)。
|
|
||||||
4. 通过 npm(推荐) 或者 yarn 安装依赖项。
|
|
||||||
5. 执行 `npm run build` 来编译 web 文件:
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/krwu/ServerStatus-web.git
|
|
||||||
cd ./ServerStatus-web/
|
|
||||||
## 你也可以用 yarn 代替下面的 npm
|
|
||||||
npm i
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
6. 把 `build` 目录下的所有文件上传到你的 ServerStatus 的 web 目录(推荐操作:你可以先删除**原目录**下除了 `json/status.json` 以外的所有文件)。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 特别鸣谢
|
|
||||||
|
|
||||||
[](https://www.jetbrains.com/?from=WebUiForServerStatus)
|
|
||||||
|
|
||||||
非常感谢 [Jetbrains](https://www.jetbrains.com/?from=WebUiForServerStatus) 对这个小小开源项目的支持!我一直是 PhpStorm 和 WebStorm 的死忠粉,它们是最棒的开发工具。
|
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
const { override, fixBabelImports } = require('customize-cra');
|
||||||
|
|
||||||
|
module.exports = override(
|
||||||
|
fixBabelImports('import', {
|
||||||
|
libraryName: 'antd',
|
||||||
|
libraryDirectory: 'es',
|
||||||
|
style: 'css',
|
||||||
|
}),
|
||||||
|
);
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"NAME": "Name",
|
|
||||||
"TYPE": "Type",
|
|
||||||
"LOC": "Location",
|
|
||||||
"UPTIME": "Uptime",
|
|
||||||
"LOAD": "Load",
|
|
||||||
"NETWORK": "Network",
|
|
||||||
"CPU": "CPU",
|
|
||||||
"RAM": "RAM",
|
|
||||||
"HDD": "HDD",
|
|
||||||
"LOADING": "Data loading...",
|
|
||||||
"WAIT": "Loading data from the server, please wait for a while...",
|
|
||||||
"LAST_UPDATE": "Last updated: {updatedTime}",
|
|
||||||
"DAYS": "days"
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"NAME": "名称",
|
|
||||||
"TYPE": "类型",
|
|
||||||
"LOC": "地区",
|
|
||||||
"UPTIME": "运行",
|
|
||||||
"LOAD": "负载",
|
|
||||||
"NETWORK": "网络",
|
|
||||||
"CPU": "CPU",
|
|
||||||
"RAM": "RAM",
|
|
||||||
"HDD": "HDD",
|
|
||||||
"LOADING": "数据加载中...",
|
|
||||||
"WAIT": "正在首次从服务器端加载监控数据,请稍候...",
|
|
||||||
"LAST_UPDATE": "数据最后更新时间:{updatedTime}",
|
|
||||||
"DAYS": "天"
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"NAME": "名稱",
|
|
||||||
"TYPE": "類型",
|
|
||||||
"LOC": "地區",
|
|
||||||
"UPTIME": "運行",
|
|
||||||
"LOAD": "負載",
|
|
||||||
"NETWORK": "網絡",
|
|
||||||
"CPU": "CPU",
|
|
||||||
"RAM": "RAM",
|
|
||||||
"HDD": "HDD",
|
|
||||||
"LOADING": "數據載入中...",
|
|
||||||
"WAIT": "正在從伺服器載入數據,請稍候...",
|
|
||||||
"LAST_UPDATE": "數據最後更新時間:{updatedTime}",
|
|
||||||
"DAYS": "天"
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
@import '~antd/dist/antd.css';
|
|
||||||
@ -1,102 +1,52 @@
|
|||||||
import "./App.css";
|
import './App.css';
|
||||||
|
|
||||||
import intl from "react-intl-universal";
|
import React, { useState, useEffect } from 'react';
|
||||||
import React, { useState, useEffect } from "react";
|
import { Layout, Row, Col, Spin } from 'antd';
|
||||||
import { Layout, Row, Col, Spin } from "antd";
|
import ServerRow from './ServerRow';
|
||||||
|
|
||||||
import ServerRow from "./ServerRow";
|
|
||||||
|
|
||||||
require("intl/locale-data/jsonp/en.js");
|
|
||||||
require("intl/locale-data/jsonp/zh.js");
|
|
||||||
|
|
||||||
const { Header, Footer, Content } = Layout;
|
const { Header, Footer, Content } = Layout;
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const [serverData, setServerData] = useState({ servers: [], updated: "0" });
|
const [serverData, setServerData] = useState({servers: [], updated: "0"});
|
||||||
const [isOnline, setIsOnline] = useState(false);
|
const [isOnline, setIsOnline] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = () => {
|
let fetchData = setInterval(() => {
|
||||||
fetch("json/stats.json")
|
fetch('json/stats.json')
|
||||||
.then((res) => res.json())
|
.then(res => res.json())
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
setServerData(data);
|
setServerData(data);
|
||||||
setIsOnline(true);
|
setIsOnline(true);
|
||||||
|
console.log(data);
|
||||||
})
|
})
|
||||||
.catch((e) => console.log("错误:", e));
|
.catch(e => console.log('错误:',e))
|
||||||
};
|
}, 2000);
|
||||||
fetchData();
|
|
||||||
let itv = setInterval(fetchData, 5000);
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(itv);
|
clearInterval(fetchData);
|
||||||
};
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [initDone, setInitDone] = useState(false);
|
|
||||||
let currentLocale = navigator.language || "zh-CN";
|
|
||||||
if (currentLocale === "zh-TW" || currentLocale === "zh-HK") {
|
|
||||||
currentLocale = "zh-TW";
|
|
||||||
} else if (currentLocale.startsWith("zh")) {
|
|
||||||
currentLocale = "zh-CN";
|
|
||||||
} else {
|
|
||||||
currentLocale = "en-US";
|
|
||||||
}
|
|
||||||
|
|
||||||
initDone ||
|
|
||||||
fetch(`locales/${currentLocale}.json`)
|
|
||||||
.then((res) => res.json())
|
|
||||||
.then((data) => {
|
|
||||||
return intl.init({
|
|
||||||
currentLocale,
|
|
||||||
locales: {
|
|
||||||
[currentLocale]: data,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
setInitDone(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<Layout>
|
<Layout>
|
||||||
<Header>
|
<Header>
|
||||||
<div className="logo">ServerStatus</div>
|
<div className="logo">ServerStatus</div>
|
||||||
</Header>
|
</Header>
|
||||||
<Content style={{ background: "#fff" }}>
|
<Content style={{background:'#fff'}}>
|
||||||
<Row justify="center">
|
<Row type="flex" justify="center">
|
||||||
<Col xs={24} sm={23} md={23} lg={22} xl={20} xxl={16}>
|
<Col xs={24} sm={23} md={23} lg={22} xl={20} xxl={16}>
|
||||||
{initDone ? (
|
<Spin size="large" spinning={!isOnline} tip="Loading...">
|
||||||
<Spin size="large" spinning={!isOnline} tip="Loading...">
|
<ServerRow {...serverData} />
|
||||||
<ServerRow {...serverData} />
|
</Spin>
|
||||||
</Spin>
|
|
||||||
) : (
|
|
||||||
<div />
|
|
||||||
)}
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Content>
|
</Content>
|
||||||
<Footer className="footer">
|
<Footer className="footer">
|
||||||
<a
|
<a href="https://udev.bid/sergate/" rel="external noopener">WebUI</a> for <a href="https://github.com/BotoX/ServerStatus/" rel="external noopener">ServerStatus</a>, made by <a href="https://www.ofcss.com/" rel="external noopener">Kairee</a>
|
||||||
href="https://github.com/krwu/ServerStatus-web"
|
|
||||||
rel="external noopener"
|
|
||||||
>
|
|
||||||
WebUI
|
|
||||||
</a>{" "}
|
|
||||||
for{" "}
|
|
||||||
<a
|
|
||||||
href="https://github.com/BotoX/ServerStatus/"
|
|
||||||
rel="external noopener"
|
|
||||||
>
|
|
||||||
ServerStatus
|
|
||||||
</a>
|
|
||||||
, made by{" "}
|
|
||||||
<a href="https://www.ofcss.com/" rel="external noopener">
|
|
||||||
Kairee
|
|
||||||
</a>
|
|
||||||
</Footer>
|
</Footer>
|
||||||
</Layout>
|
</Layout>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
import { StrictMode } from 'react';
|
import React from 'react';
|
||||||
import { createRoot } from 'react-dom/client';
|
import ReactDOM from 'react-dom';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
// import reportWebVitals from './reportWebVitals';
|
import * as serviceWorker from './serviceWorker';
|
||||||
|
|
||||||
const el = document.getElementById('root');
|
ReactDOM.render(<App />, document.getElementById('root'));
|
||||||
if (el === null) {
|
|
||||||
throw new Error('root container missing in index.html');
|
|
||||||
}
|
|
||||||
const root = createRoot(el);
|
|
||||||
root.render(<StrictMode><App /></StrictMode>);
|
|
||||||
|
|
||||||
// If you want to start measuring performance in your app, pass a function
|
// If you want your app to work offline and load faster, you can change
|
||||||
// to log results (for example: reportWebVitals(console.log))
|
// unregister() to register() below. Note this comes with some pitfalls.
|
||||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||||
// reportWebVitals();
|
serviceWorker.unregister();
|
||||||
|
|||||||
@ -0,0 +1,143 @@
|
|||||||
|
// This optional code is used to register a service worker.
|
||||||
|
// register() is not called by default.
|
||||||
|
|
||||||
|
// This lets the app load faster on subsequent visits in production, and gives
|
||||||
|
// it offline capabilities. However, it also means that developers (and users)
|
||||||
|
// will only see deployed updates on subsequent visits to a page, after all the
|
||||||
|
// existing tabs open on the page have been closed, since previously cached
|
||||||
|
// resources are updated in the background.
|
||||||
|
|
||||||
|
// To learn more about the benefits of this model and instructions on how to
|
||||||
|
// opt-in, read https://bit.ly/CRA-PWA
|
||||||
|
|
||||||
|
const isLocalhost = Boolean(
|
||||||
|
window.location.hostname === 'localhost' ||
|
||||||
|
// [::1] is the IPv6 localhost address.
|
||||||
|
window.location.hostname === '[::1]' ||
|
||||||
|
// 127.0.0.1/8 is considered localhost for IPv4.
|
||||||
|
window.location.hostname.match(
|
||||||
|
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
type Config = {
|
||||||
|
onSuccess?: (registration: ServiceWorkerRegistration) => void;
|
||||||
|
onUpdate?: (registration: ServiceWorkerRegistration) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function register(config?: Config) {
|
||||||
|
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||||
|
// The URL constructor is available in all browsers that support SW.
|
||||||
|
const publicUrl = new URL(
|
||||||
|
(process as { env: { [key: string]: string } }).env.PUBLIC_URL,
|
||||||
|
window.location.href
|
||||||
|
);
|
||||||
|
if (publicUrl.origin !== window.location.origin) {
|
||||||
|
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||||
|
// from what our page is served on. This might happen if a CDN is used to
|
||||||
|
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||||
|
|
||||||
|
if (isLocalhost) {
|
||||||
|
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||||
|
checkValidServiceWorker(swUrl, config);
|
||||||
|
|
||||||
|
// Add some additional logging to localhost, pointing developers to the
|
||||||
|
// service worker/PWA documentation.
|
||||||
|
navigator.serviceWorker.ready.then(() => {
|
||||||
|
console.log(
|
||||||
|
'This web app is being served cache-first by a service ' +
|
||||||
|
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Is not localhost. Just register service worker
|
||||||
|
registerValidSW(swUrl, config);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerValidSW(swUrl: string, config?: Config) {
|
||||||
|
navigator.serviceWorker
|
||||||
|
.register(swUrl)
|
||||||
|
.then(registration => {
|
||||||
|
registration.onupdatefound = () => {
|
||||||
|
const installingWorker = registration.installing;
|
||||||
|
if (installingWorker == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
installingWorker.onstatechange = () => {
|
||||||
|
if (installingWorker.state === 'installed') {
|
||||||
|
if (navigator.serviceWorker.controller) {
|
||||||
|
// At this point, the updated precached content has been fetched,
|
||||||
|
// but the previous service worker will still serve the older
|
||||||
|
// content until all client tabs are closed.
|
||||||
|
console.log(
|
||||||
|
'New content is available and will be used when all ' +
|
||||||
|
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Execute callback
|
||||||
|
if (config && config.onUpdate) {
|
||||||
|
config.onUpdate(registration);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// At this point, everything has been precached.
|
||||||
|
// It's the perfect time to display a
|
||||||
|
// "Content is cached for offline use." message.
|
||||||
|
console.log('Content is cached for offline use.');
|
||||||
|
|
||||||
|
// Execute callback
|
||||||
|
if (config && config.onSuccess) {
|
||||||
|
config.onSuccess(registration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error during service worker registration:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||||
|
// Check if the service worker can be found. If it can't reload the page.
|
||||||
|
fetch(swUrl)
|
||||||
|
.then(response => {
|
||||||
|
// Ensure service worker exists, and that we really are getting a JS file.
|
||||||
|
const contentType = response.headers.get('content-type');
|
||||||
|
if (
|
||||||
|
response.status === 404 ||
|
||||||
|
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||||
|
) {
|
||||||
|
// No service worker found. Probably a different app. Reload the page.
|
||||||
|
navigator.serviceWorker.ready.then(registration => {
|
||||||
|
registration.unregister().then(() => {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Service worker found. Proceed as normal.
|
||||||
|
registerValidSW(swUrl, config);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
console.log(
|
||||||
|
'No internet connection found. App is running in offline mode.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unregister() {
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker.ready.then(registration => {
|
||||||
|
registration.unregister();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,26 +1,25 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
"dom.iterable",
|
"dom.iterable",
|
||||||
"esnext"
|
"esnext"
|
||||||
],
|
],
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"module": "esnext",
|
||||||
"module": "esnext",
|
"moduleResolution": "node",
|
||||||
"moduleResolution": "node",
|
"resolveJsonModule": true,
|
||||||
"resolveJsonModule": true,
|
"isolatedModules": true,
|
||||||
"isolatedModules": true,
|
"noEmit": true,
|
||||||
"noEmit": true,
|
"jsx": "react"
|
||||||
"jsx": "react-jsx"
|
},
|
||||||
},
|
"include": [
|
||||||
"include": [
|
"src"
|
||||||
"src"
|
]
|
||||||
]
|
}
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue