fix: replace http-serve with serve-handler (#122)

* fix: replace http-serve with serve package

Replaces the http-serve package to properly handle the single page routing

* feat: add cache invalidation

* fix: add serve command in bin

* fix: remove serve package dependency

* chore: applied PR review suggestions

Co-authored-by: Vojtech Simetka <vojtech@simetka.cz> (+1 squashed commit)
Squashed commits:
[d73baf4] Update serve.js

Co-authored-by: Vojtech Simetka <vojtech@simetka.cz>

Co-authored-by: Vojtech Simetka <vojtech@simetka.cz>
This commit is contained in:
Matt Mertens
2021-05-31 00:57:44 -07:00
committed by GitHub
parent 07f987e069
commit ba9b498488
4 changed files with 148 additions and 21622 deletions
+109 -21614
View File
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -33,8 +33,8 @@
"axios": "^0.21.1", "axios": "^0.21.1",
"bignumber.js": "^9.0.1", "bignumber.js": "^9.0.1",
"feather-icons": "^4.28.0", "feather-icons": "^4.28.0",
"http-serve": "^1.0.1",
"material-ui-dropzone": "^3.5.0", "material-ui-dropzone": "^3.5.0",
"opener": "^1.5.2",
"qrcode.react": "^1.0.1", "qrcode.react": "^1.0.1",
"react": "^17.0.2", "react": "^17.0.2",
"react-copy-to-clipboard": "^5.0.3", "react-copy-to-clipboard": "^5.0.3",
@@ -42,7 +42,8 @@
"react-feather": "^2.0.9", "react-feather": "^2.0.9",
"react-identicons": "^1.2.5", "react-identicons": "^1.2.5",
"react-router-dom": "^5.2.0", "react-router-dom": "^5.2.0",
"react-syntax-highlighter": "^15.4.3" "react-syntax-highlighter": "^15.4.3",
"serve-handler": "^6.1.3"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^5.12.0", "@testing-library/jest-dom": "^5.12.0",
@@ -70,7 +71,7 @@
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"serve": "http-serve ./build -o", "serve": "node ./serve.js",
"lint": "eslint --fix \"src/**/*.ts\" \"src/**/*.tsx\" && prettier --write \"src/**/*.ts\" \"src/**/*.tsx\"", "lint": "eslint --fix \"src/**/*.ts\" \"src/**/*.tsx\" && prettier --write \"src/**/*.ts\" \"src/**/*.tsx\"",
"lint:check": "eslint \"src/**/*.ts\" \"src/**/*.tsx\" && prettier --check \"src/**/*.ts\" \"src/**/*.tsx\"" "lint:check": "eslint \"src/**/*.ts\" \"src/**/*.tsx\" && prettier --check \"src/**/*.ts\" \"src/**/*.tsx\""
}, },
+12
View File
@@ -0,0 +1,12 @@
{
"trailingSlash": false,
"headers": [
{
"source" : "*",
"headers" : [{
"key" : "Cache-Control",
"value" : "max-age=3600"
}]
}
]
}
Executable → Regular
+22 -4
View File
@@ -1,15 +1,33 @@
#!/usr/bin/env node #!/usr/bin/env node
const path = require('path') const path = require('path')
const serve = require('http-serve') const handler = require('serve-handler');
const http = require('http');
const opener = require('opener') const opener = require('opener')
const server = serve.createServer({ const serverConfig = {
root: path.join(__dirname, 'build') public: path.join(__dirname, 'build'),
trailingSlash: false,
rewrites: [
{ source: "**", destination: "/index.html" },
],
headers: [
{
source: "*",
headers: [{
key: "Cache-Control",
value: "max-age=3600"
}]
}
]
}
const server = http.createServer((request, response) => {
return handler(request, response, serverConfig);
}) })
server.listen(8080, '127.0.0.1', function () { server.listen(8080, () => {
console.log('Starting up Bee Dashboard on address http://localhost:8080') console.log('Starting up Bee Dashboard on address http://localhost:8080')
console.log('Hit CTRL-C to stop the server') console.log('Hit CTRL-C to stop the server')
opener('http://localhost:8080') opener('http://localhost:8080')