diff --git a/client/package.json b/client/package.json index c183172..16b9191 100644 --- a/client/package.json +++ b/client/package.json @@ -2,6 +2,7 @@ "name": "music-resource-pack-creator-client", "version": "0.1.0", "private": true, + "proxy": "http://localhost:3001", "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.1.1", "@fortawesome/free-solid-svg-icons": "^6.1.1", diff --git a/client/src/api.ts b/client/src/api.ts index 262049c..0bbbee2 100644 --- a/client/src/api.ts +++ b/client/src/api.ts @@ -1,6 +1,4 @@ -const URL = "http://localhost:3001" - export interface Disc { title?: string description?: string @@ -13,7 +11,7 @@ export interface CreatePackPayload { } export async function getTitle(url: string): Promise { - const res = await fetch(`${URL}/get-title`, { + const res = await fetch(`/get-title`, { method: "POST", body: url, }) @@ -25,7 +23,7 @@ export async function getTitle(url: string): Promise { } export async function createPack(info: CreatePackPayload) { - const res = await fetch(`${URL}/create`, { + const res = await fetch(`/create`, { method: "POST", mode: "cors", headers: { "Content-Type" : "application/json" }, @@ -35,7 +33,6 @@ export async function createPack(info: CreatePackPayload) { if (res.status == 200) { return await res.blob() } else { - console.log(res) return undefined } } diff --git a/package.json b/package.json index 4b130e6..6d2bf44 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,16 @@ "license": "MIT", "private": true, "scripts": { - "start": "NODE_ENV=production node dist/index.js", + "start": "NODE_ENV=production ts-node src/index.ts", "dev": "NODE_ENV=development nodemon src/index.ts", - "build": "tsc" + "build": "cd client && yarn && yarn build" }, "dependencies": { "@hapi/hapi": "^20.2.1", + "@hapi/inert": "^6.0.5", "@types/fluent-ffmpeg": "^2.1.20", "@types/hapi__hapi": "^20.0.10", + "@types/hapi__inert": "^5.2.3", "@types/node": "^17.0.23", "@types/temp": "^0.9.1", "fluent-ffmpeg": "^2.1.2", diff --git a/src/index.ts b/src/index.ts index 3e344e1..5ebf455 100644 --- a/src/index.ts +++ b/src/index.ts @@ -163,9 +163,16 @@ function addCreateRoute(server: hapi.Server) { } async function main() { + let host = undefined + let port = process.env.PORT || 3000 + if (process.env.NODE_ENV == "development") { + host = "localhost" + port = 3001 + } + const server = hapi.server({ - port: process.env.PORT || 3000, - host: 'localhost', + port, + host, routes: { cors: true } @@ -174,6 +181,18 @@ async function main() { addGetTitleRoute(server) addCreateRoute(server) + await server.register(require('@hapi/inert')) + + server.route({ + method: "GET", + path: "/{param*}", + handler: { + directory: { + path: "client/build" + } + } + }) + await server.start() console.log("Server running on %s", server.info.uri) } diff --git a/tsconfig.json b/tsconfig.json index 2511d7e..9cd6a34 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,8 +6,8 @@ "esModuleInterop": true, "downlevelIteration": true, "experimentalDecorators": true, - "baseUrl": "src", - "outDir": "dist", + "baseUrl": "/src", + "outDir": "/dist", "rootDirs": ["src"], "paths": { "~/*": ["*"] diff --git a/yarn.lock b/yarn.lock index da5b8d3..0796577 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,7 +22,7 @@ "@hapi/boom" "9.x.x" "@hapi/hoek" "9.x.x" -"@hapi/ammo@^5.0.1": +"@hapi/ammo@5.x.x", "@hapi/ammo@^5.0.1": version "5.0.1" resolved "https://registry.yarnpkg.com/@hapi/ammo/-/ammo-5.0.1.tgz#9d34560f5c214eda563d838c01297387efaab490" integrity sha512-FbCNwcTbnQP4VYYhLNGZmA76xb2aHg9AMPiy18NZyWMG310P5KdFGyA9v2rm5ujrIny77dEEIkMOwl0Xv+fSSA== @@ -139,6 +139,18 @@ resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.2.1.tgz#9551142a1980503752536b5050fd99f4a7f13b17" integrity sha512-gfta+H8aziZsm8pZa0vj04KO6biEiisppNgA1kbJvFrrWu9Vm7eaUEy76DIxsuTaWvti5fkJVhllWc6ZTE+Mdw== +"@hapi/inert@^6.0.5": + version "6.0.5" + resolved "https://registry.yarnpkg.com/@hapi/inert/-/inert-6.0.5.tgz#0c5a28e9b5a637d3d47419859bb7163d0b194a61" + integrity sha512-eVAdUVhJLmmXLM/Zt7u5H5Vzazs9GKe4zfPK2b97ePHEfs3g/AQkxHfYQjJqMy11hvyB7a21Z6rBEA0R//dtXw== + dependencies: + "@hapi/ammo" "5.x.x" + "@hapi/boom" "9.x.x" + "@hapi/bounce" "2.x.x" + "@hapi/hoek" "9.x.x" + "@hapi/validate" "1.x.x" + lru-cache "^6.0.0" + "@hapi/iron@6.x.x", "@hapi/iron@^6.0.0": version "6.0.0" resolved "https://registry.yarnpkg.com/@hapi/iron/-/iron-6.0.0.tgz#ca3f9136cda655bdd6028de0045da0de3d14436f" @@ -325,7 +337,7 @@ resolved "https://registry.yarnpkg.com/@types/hapi__catbox/-/hapi__catbox-10.2.4.tgz#4d0531a6c2d0e45024f724020d536041ef8ffe30" integrity sha512-A6ivRrXD5glmnJna1UAGw87QNZRp/vdFO9U4GS+WhOMWzHnw+oTGkMvg0g6y1930CbeheGOCm7A1qHsqH7AXqg== -"@types/hapi__hapi@^20.0.10": +"@types/hapi__hapi@*", "@types/hapi__hapi@^20.0.10": version "20.0.10" resolved "https://registry.yarnpkg.com/@types/hapi__hapi/-/hapi__hapi-20.0.10.tgz#890d8d5c3b12337ba6e4ea9e33d8aec5d62bbc25" integrity sha512-Nt/SY/20/JAlHhbgH616j0g18vsANR9OWoyMdQcytlW6o7TBN+wRgf0MB8AgzjYpuzQam5oTiqyED9WwHmQKYQ== @@ -339,6 +351,13 @@ "@types/node" "*" joi "^17.3.0" +"@types/hapi__inert@^5.2.3": + version "5.2.3" + resolved "https://registry.yarnpkg.com/@types/hapi__inert/-/hapi__inert-5.2.3.tgz#f586eb240d5997c9968d1b4e8b37679517045ca1" + integrity sha512-I1mWQrEc7oMqGtofT0rwBgRBCBurz0wNzbq8QZsHWR+aXM0bk1j9GA6zwyGIeO53PNl2C1c2kpXlc084xCV+Tg== + dependencies: + "@types/hapi__hapi" "*" + "@types/hapi__mimos@*": version "4.1.4" resolved "https://registry.yarnpkg.com/@types/hapi__mimos/-/hapi__mimos-4.1.4.tgz#4f8a1c58345fc468553708d3cb508724aa081bd9" @@ -907,6 +926,13 @@ lowercase-keys@^2.0.0: resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479" integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA== +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== + dependencies: + yallist "^4.0.0" + lru-cache@^7.4.0: version "7.8.0" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.8.0.tgz#649aaeb294a56297b5cbc5d70f198dcc5ebe5747" @@ -1370,6 +1396,11 @@ xdg-basedir@^4.0.0: resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-4.0.0.tgz#4bc8d9984403696225ef83a1573cbbcb4e79db13" integrity sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q== +yallist@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" + integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== + yn@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"