Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
CPAL-1.0 License

The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/ir-engine/ir-engine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.

The Original Code is Infinite Reality Engine.

The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Infinite Reality Engine team.

All portions of the code written by the Infinite Reality Engine team are Copyright © 2021-2023
Infinite Reality Engine. All Rights Reserved.
*/

import { koa } from '@feathersjs/koa'
import packageRoot from 'app-root-path'
import dotenv from 'dotenv'
import { createServer as _createServer } from 'http'
import { createServer } from 'https'
import send from 'koa-send'
import serve from 'koa-static'
import { readFileSync } from 'node:fs'
import path from 'path'

const cwd = process.cwd()

dotenv.config({ path: cwd + '/.env.local' })

const app = new koa()
const PORT = parseInt(process.env.VITE_CLIENT_PORT) || 3000
const HTTPS = process.env.HTTPS ?? false
const key = process.env.KEY || 'certs/key.pem'
const cert = process.env.CERT || 'certs/cert.pem'

app.use(
serve(path.join(cwd, 'dist'), {
brotli: true,
setHeaders: (ctx) => {
ctx.setHeader('Origin-Agent-Cluster', '?1')
}
})
)

app.use(async (ctx) => {
await send(ctx, path.join('dist', 'index.html'), {
root: cwd
})
})

app.listen = function () {
let server
if (HTTPS) {
const pathedkey = readFileSync(path.join(packageRoot.path, key))
const pathedcert = readFileSync(path.join(packageRoot.path, cert))
server = createServer({ key: pathedkey, cert: pathedcert }, this.callback())
} else {
server = _createServer(this.callback())
}
return server.listen.apply(server, arguments)
}
app.listen(PORT, () => console.log(`Server listening on port: ${PORT}`))
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"scripts": {
"test": "exit 0",
"check-errors": "tsc --noemit",
"dev": "cross-env APP_ENV=development NODE_OPTIONS=--max_old_space_size=20480 vite",
"build": "cross-env NODE_OPTIONS=--max_old_space_size=10240 vite build",
"start": "ts-node server.js",
"dev": "cross-env APP_ENV=development concurrently -n client,server -c '#FF9800,#A2789C' \"npm run dev-client\" \"npm run dev-server\" ",
"dev-client": "cd ../../../../client && cross-env NODE_OPTIONS=--max_old_space_size=10240 PROJECT_NAME='ir-engine/ir-static-build-template' APP_ENV=development vite --config ./static.vite.config.ts",
"dev-server": "cross-env APP_ENV=development NODE_OPTIONS=--max_old_space_size=20480 PROJECT_NAME='ir-engine/ir-static-build-template' ts-node --swc ../../../../server-core/src/simple/server.ts",
"build": "cd ../../../../client && cross-env NODE_OPTIONS=--max_old_space_size=10240 PROJECT_NAME='ir-engine/ir-static-build-template' vite build --config ./static.vite.config.ts",
"start": "ts-node --swc client.js",
"server": "ts-node --swc ../../../../server-core/src/simple/server.ts",
"format": "prettier --write \"**/*.{ts,tsx}\"",
"format-scss": "stylelint \"**/*.scss\" --fix",
"format-staged": "lint-staged",
Expand Down