pages235/server.js
Vitaly 9b72cdb8f0
feat: migrate to mc-assets & Rsbuild better resource pack support (#164)
The complete migration from `minecraft-assets` to [`mc-assets`](https://npmjs.com/mc-assets).

Now all block states & block models are processed dynamically! So it is now easily possible to implement custom models

- no post-install work anymore: the building is now 3x faster and 4x faster in docker
- drop 10x total deploy size
- display world ~1.5x faster
- fix snow & repeater state parser (they didn't render correctly)

rsbuild pipeline!

- the initial app load is faster ~1.2
- much fewer requests are made & cached
- dev reloads are fast now

Resource pack changes:

- now textures are reloaded much more quickly on the fly
- add hotkey to quickly reload textures (for debugging) assigned to F3+T (open dev widget is now assigned to F3+Y)
- add a way to disable resource pack instead of uninstalling it
- items render from resource pack are now support
- resource pack widgets & icons are now supported
2024-07-26 13:12:28 +03:00

72 lines
2.1 KiB
JavaScript

#!/usr/bin/env node
const express = require('express')
const netApi = require('net-browserify')
const compression = require('compression')
const path = require('path')
const cors = require('cors')
const https = require('https')
const fs = require('fs')
let siModule
try {
siModule = require('systeminformation')
} catch (err) { }
// Create our app
const app = express()
const isProd = process.argv.includes('--prod')
app.use(compression())
app.use(netApi({ allowOrigin: '*' }))
if (!isProd) {
app.use('/sounds', express.static(path.join(__dirname, './generated/sounds/')))
}
// patch config
app.get('/config.json', (req, res, next) => {
// read original file config
let config = {}
try {
config = require('./config.json')
} catch {
try {
config = require('./dist/config.json')
} catch { }
}
res.json({
...config,
'defaultProxy': '', // use current url (this server)
})
})
if (isProd) {
// add headers to enable shared array buffer
app.use((req, res, next) => {
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
next()
})
app.use(express.static(path.join(__dirname, './dist')))
}
const numArg = process.argv.find(x => x.match(/^\d+$/))
const port = (require.main === module ? numArg : undefined) || 8080
// Start the server
const server =
app.listen(port, async function () {
console.log('Proxy server listening on port ' + server.address().port)
if (siModule && isProd) {
const _interfaces = await siModule.networkInterfaces()
const interfaces = Array.isArray(_interfaces) ? _interfaces : [_interfaces]
let netInterface = interfaces.find(int => int.default)
if (!netInterface) {
netInterface = interfaces.find(int => !int.virtual) ?? interfaces[0]
console.warn('Failed to get the default network interface, searching for fallback')
}
if (netInterface) {
const address = netInterface.ip4
console.log(`You can access the server on http://localhost:${port} or http://${address}:${port}`)
}
}
})
module.exports = { app }