-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(webapp): migrate server project to server.ts
- Loading branch information
Showing
62 changed files
with
494 additions
and
304 deletions.
There are no files selected for viewing
Binary file added
BIN
+34.1 KB
.yarn/cache/@cspotcode-source-map-support-npm-0.8.1-964f2de99d-5718f26708.zip
Binary file not shown.
Binary file added
BIN
+27.5 KB
.yarn/cache/@jridgewell-trace-mapping-npm-0.3.9-91625cd7fb-d89597752f.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+2.56 KB
.yarn/cache/@types-strip-json-comments-npm-0.0.30-4d685379c3-829ddd3896.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,40 +13,29 @@ Open StarTer Village - Web App is a single-page application project designed for | |
git clone [email protected]:ocftw/open-star-ter-village.git open-star-ter-village | ||
``` | ||
|
||
> Note: Open StarTer Village Game requires node >= 12.0.0 | ||
> Note: Open StarTer Village Game requires node >= 18.0.0 | ||
### Get Started | ||
|
||
```shell | ||
yarn | ||
yarn build:webapp | ||
yarn deploy:webapp | ||
yarn start:webapp | ||
yarn run webapp install | ||
yarn run webapp build | ||
yarn run webapp start | ||
``` | ||
|
||
## Deployment Options | ||
|
||
### Deploying to Heroku (Please note, we are exploring alternative solutions to Heroku due to certain limitations) | ||
### Deploy to Vercel | ||
|
||
```shell | ||
heroku create | ||
git push heroku main | ||
heroku open | ||
``` | ||
|
||
or | ||
|
||
[![Deploy to Heroku (Exploring Alternative Solutions)](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/ocftw/open-star-ter-village/tree/main) | ||
TBD - We are working on this feature. | ||
|
||
## How to Contribute to the Source Code | ||
|
||
Open StarTer Village - WebApp is a TypeScript monorepo configured with Yarn 2 using the workspace-tools plugin. The core game engine is based on [boardgame.io](https://boardgame.io) on both the server and client side. The Open StarTer Village - WebApp project is divided into three parts: core game logic, client UI, and the game server. Below is a table showing their npm project names and locations: | ||
|
||
| Project Name | Description | | ||
| ---------------------------------------------- | -------------------- | | ||
| [`@open-star-ter-village/webapp-game`](./packages/game/) | The core game logic | | ||
| [`@open-star-ter-village/webapp-client`](./client/) | The client UI | | ||
| [`@open-star-ter-village/webapp-server`](./server/) | The game server | | ||
| Project Name | Description | | ||
| ---------------------------------------------- | ----------------------- | | ||
| [`@open-star-ter-village/webapp`](./packages/webapp/) | The web game app | | ||
|
||
### How to Start the Local Development Environment | ||
|
||
|
@@ -57,32 +46,31 @@ Open StarTer Village - Web App uses Yarn 2 workspaces to manage the project. Ple | |
The following command will start the client UI (Create React App) on a development server, the server (Koa) using ts-node with watchmon, and the game core (pure TypeScript) in watch compile mode. | ||
|
||
```shell | ||
yarn dev:webapp | ||
yarn run webapp dev | ||
``` | ||
|
||
Everything is set up and ready for you to start coding! | ||
|
||
#### Local Build | ||
|
||
Open StarTer Village - Web App has three primary outcomes: `client` and `server`, which serve the game on the platform, and other outputs used as libraries in parts of `client` and `server`. | ||
The following command will build nextjs webapp into `packages/webapp/.next` and server into `packages/webapp/dist`. | ||
|
||
```shell | ||
yarn build:webapp | ||
yarn run webapp build | ||
``` | ||
|
||
Project output table | ||
| Project Name | Output Location | Description | | ||
| -------------------------------------------- | ----------------------- | ----------------------- | | ||
| `@open-star-ter-village/webapp-game` | ./packages/game/dist | The core game logic | | ||
| `@open-star-ter-village/webapp-client` | ./client/build | The client UI | | ||
| `@open-star-ter-village/webapp-server` | ./server/build | The game server | | ||
#### Local Start | ||
|
||
> Note: The output folders are ignored by Git, but you can find them after the build process. | ||
After building the project, you can start the server and webapp with the following command: | ||
|
||
```shell | ||
yarn run webapp start | ||
``` | ||
|
||
#### Unit Test (Currently not available) | ||
#### Unit Test (Currently only available for game core) | ||
|
||
```shell | ||
yarn test | ||
yarn run webapp test | ||
``` | ||
|
||
## How to Contribute to Assets | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Server, Origins } from "boardgame.io/server"; | ||
import next from 'next'; | ||
import url from "url"; | ||
import { OpenStarTerVillage } from "./game"; | ||
|
||
async function serve() { | ||
const port = Number(process.env.PORT) || 8000; | ||
const apiPort = Number(process.env.API_PORT) || 8080; | ||
const dev = process.env.NODE_ENV !== 'production'; | ||
const app = next({ dev }); | ||
const handle = app.getRequestHandler(); | ||
|
||
const server = Server({ | ||
games: [OpenStarTerVillage], | ||
origins: [ | ||
// Allow localhost to connect, except when NODE_ENV is 'production'. | ||
Origins.LOCALHOST_IN_DEVELOPMENT, | ||
], | ||
}); | ||
const mainServerConfig = { | ||
port, | ||
callback: () => console.log(`Main server running on port ${port}...`), | ||
}; | ||
const lobbyConfig = { | ||
apiPort, | ||
apiCallback: () => console.log(`Lobby api running on port ${apiPort}`), | ||
}; | ||
|
||
await app.prepare(); | ||
server.run({ | ||
...mainServerConfig, | ||
lobbyConfig, | ||
}, () => { | ||
server.app.use(async (ctx, next) => { | ||
const parsedUrl = url.parse(ctx.req.url!, true); | ||
await handle(ctx.req, ctx.res, parsedUrl); | ||
ctx.respond = false; | ||
await next(); | ||
}); | ||
}); | ||
} | ||
|
||
serve(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2017", | ||
"module": "commonjs", | ||
"lib": ["ES2017"], | ||
"outDir": "./dist", | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
}, | ||
"include": ["./src/server.ts", "./src/game/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.