Skip to content

Commit

Permalink
feat(react): add custom domain (#190)
Browse files Browse the repository at this point in the history
Implement of winglang/wing#6178

I also deleted `get-port` from the code, it causes a compilation error (in addition to not being used at the moment):

```
Error: require() of ES Module /Users/meir/Documents/GitHub/winglibs2/react/node_modules/get-port/index.js from /Users/meir/Documents/GitHub/winglibs2/react/utils.js not supported.
Instead change the require of index.js in /Users/meir/Documents/GitHub/winglibs2/react/utils.js to a dynamic import() which is available in all CommonJS modules.
```
  • Loading branch information
meirdev authored Apr 9, 2024
1 parent 6d91775 commit 09de4ab
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 8 deletions.
2 changes: 2 additions & 0 deletions react/api.w
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct AppPros {
buildCommand: str?;
// In sim, if `true` - will use the start command, and if `false` - the build command.
useBuildCommand: bool?;
// The website's custom domain object.
domain: cloud.Domain?;
}

pub interface IApp {
Expand Down
2 changes: 1 addition & 1 deletion react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@winglibs/react",
"description": "React library for Wing",
"version": "0.0.1",
"version": "0.0.2",
"author": {
"name": "Meir Elbaz",
"email": "[email protected]"
Expand Down
2 changes: 0 additions & 2 deletions react/sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub class AppSim extends api.AppBase impl api.IApp {
this.url = state.token("url");

let service = new cloud.Service(inflight () => {
// TODO: solution for test environment
// let var port = utils.Utils.getPort();
let port = props.localPort ?? 3001;

state.set("url", "http://localhost:{port}");
Expand Down
1 change: 1 addition & 0 deletions react/tf-aws.w
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub class AppTfAws extends api.AppBase impl api.IApp {
this.website = new cloud.Website(
path: this.buildDir,
errorDocument: "index.html",
domain: this.props.domain,
);
}

Expand Down
1 change: 0 additions & 1 deletion react/utils.extern.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default interface extern {
exec: (command: string, env: Record<string, string>, cwd: string) => Promise<() => Promise<void>>,
execSync: (command: string, env: Record<string, string>, cwd: string) => void,
getPort: () => Promise<number>,
serveStaticFiles: (path: string, port: number) => Promise<() => Promise<void>>,
}
3 changes: 0 additions & 3 deletions react/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ const child_process = require("node:child_process");
const http = require("node:http");

const finalhandler = require("finalhandler");
const getPort = require("get-port");
const serveStatic = require("serve-static");
const treeKill = require("tree-kill");

exports.getPort = getPort;

exports.exec = (command, env, cwd) => {
process.env.NODE_NO_WARNINGS = "1"; // disable deprecation warnings

Expand Down
1 change: 0 additions & 1 deletion react/utils.w
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub class Utils {
pub static extern "./utils.js" inflight getPort(): num;
pub static extern "./utils.js" inflight exec(command: str, env: MutMap<str>, cwd: str): inflight(): void;
pub static extern "./utils.js" inflight serveStaticFiles(path: str, port: num): inflight (): void;
pub static extern "./utils.js" execSync(command: str, env: MutMap<str>, cwd: str): void;
Expand Down

0 comments on commit 09de4ab

Please sign in to comment.