diff --git a/waspc/data/Generator/templates/server/src/routes/index.js b/waspc/data/Generator/templates/server/src/routes/index.js index c2872efd4c..7b3eed4c84 100644 --- a/waspc/data/Generator/templates/server/src/routes/index.js +++ b/waspc/data/Generator/templates/server/src/routes/index.js @@ -11,14 +11,32 @@ import apis from './apis/index.js' {=# areThereAnyCrudRoutes =} import { rootCrudRouter } from './crud/index.js' {=/ areThereAnyCrudRoutes =} +{=# isDevelopment =} +import { config } from 'wasp/server' +import { makeWrongPortPage } from '../views/wrong-port.js' +{=/ isDevelopment =} const router = express.Router() const middleware = globalMiddlewareConfigForExpress() -router.get('/', middleware, function (_req, res) { - res.status(200).send(); -}) +router.get('/', middleware, + {=# isDevelopment =} + function (_req, res) { + const data = { + appName: "{= appName =}", + frontendUrl: config.frontendUrl + }; + const wrongPortPage = makeWrongPortPage(data); + res.status(200).type('html').send(wrongPortPage); + } + {=/ isDevelopment =} + {=^ isDevelopment =} + function (_req, res) { + res.status(200).send(); + } + {=/ isDevelopment =} +) {=# isAuthEnabled =} router.use('/auth', middleware, auth) diff --git a/waspc/data/Generator/templates/server/src/views/wrong-port.ts b/waspc/data/Generator/templates/server/src/views/wrong-port.ts new file mode 100644 index 0000000000..c785cd4066 --- /dev/null +++ b/waspc/data/Generator/templates/server/src/views/wrong-port.ts @@ -0,0 +1,123 @@ +/* + This template gets rendered when you visit the root route on the server (i.e. + http://localhost:3001/) in development mode. + + Some of the data passed to this template is known at runtime and not compile + time, so we need to craft the string at runtime with a JS template string. We + explicitly do not use Wasp mustaches here so we don't have to reason about two + different templating systems. + + For now, we don't serve any other static files in our routes, so all the + resources needed (CSS, images, etc.) must be inlined into the file. +*/ + +// The /* HTML */ comment is a hint to `prettier` to format this string as HTML. +export const makeWrongPortPage = ({ + appName, + frontendUrl, +}: { + appName: string; + frontendUrl: string; +}): string => /* HTML */ ` + + + + + + ${appName} API Server + + + + +
+
+

+ + + + + + Wasp +

+
+ +
+

${appName} API Server

+

+ The server is up and running. This is the backend part of your Wasp + application. +

+

+ If you want to visit your frontend application, go to this URL in + your browser: +

+ +

${frontendUrl}

+
+

+ + This message is shown because you are running the server in + development mode. In production, this route would not show + anything. + +

+
+
+ + +`; diff --git a/waspc/e2e-tests/snapshots/kitchen-sink-golden/snapshot-file-list.manifest b/waspc/e2e-tests/snapshots/kitchen-sink-golden/snapshot-file-list.manifest index 946c61e732..037ef4b97e 100644 --- a/waspc/e2e-tests/snapshots/kitchen-sink-golden/snapshot-file-list.manifest +++ b/waspc/e2e-tests/snapshots/kitchen-sink-golden/snapshot-file-list.manifest @@ -1131,6 +1131,7 @@ wasp-app/.wasp/out/server/src/routes/operations/updateTaskIsDone.js wasp-app/.wasp/out/server/src/routes/operations/voidToStringAuth.js wasp-app/.wasp/out/server/src/routes/operations/voidToStringNoAuth.js wasp-app/.wasp/out/server/src/server.ts +wasp-app/.wasp/out/server/src/views/wrong-port.ts wasp-app/.wasp/out/server/src/webSocket/initialization.ts wasp-app/.wasp/out/server/tsconfig.json wasp-app/.wasp/out/web-app/.env diff --git a/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/.waspchecksums b/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/.waspchecksums index 349b125fc5..77b708960e 100644 --- a/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/.waspchecksums +++ b/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/.waspchecksums @@ -1999,7 +1999,7 @@ "file", "server/src/routes/index.js" ], - "91e02dad5992e7dbbe618c034d23b55025fb2dbd060d209b8b1e18779809b748" + "418a9575769e4b3d575e44a0d714d79ff8800f79c509775d57bf1a075bf7447f" ], [ [ @@ -2225,6 +2225,13 @@ ], "02e7667fbb7959f6272b91ba0e481a26e0454230e384b841864855ebb8e6042a" ], + [ + [ + "file", + "server/src/views/wrong-port.ts" + ], + "cc8fc19e919c4d22ec6095a60446dd4f52dc864112e6b379ae35ec45c5b04b16" + ], [ [ "file", diff --git a/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/server/src/routes/index.js b/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/server/src/routes/index.js index 8cb29b5484..6351c7153e 100644 --- a/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/server/src/routes/index.js +++ b/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/server/src/routes/index.js @@ -4,14 +4,23 @@ import { globalMiddlewareConfigForExpress } from '../middleware/index.js' import auth from './auth/index.js' import apis from './apis/index.js' import { rootCrudRouter } from './crud/index.js' +import { config } from 'wasp/server' +import { makeWrongPortPage } from '../views/wrong-port.js' const router = express.Router() const middleware = globalMiddlewareConfigForExpress() -router.get('/', middleware, function (_req, res) { - res.status(200).send(); -}) +router.get('/', middleware, + function (_req, res) { + const data = { + appName: "KitchenSink", + frontendUrl: config.frontendUrl + }; + const wrongPortPage = makeWrongPortPage(data); + res.status(200).type('html').send(wrongPortPage); + } +) router.use('/auth', middleware, auth) router.use('/operations', middleware, operations) diff --git a/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts b/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts new file mode 100644 index 0000000000..c785cd4066 --- /dev/null +++ b/waspc/e2e-tests/snapshots/kitchen-sink-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts @@ -0,0 +1,123 @@ +/* + This template gets rendered when you visit the root route on the server (i.e. + http://localhost:3001/) in development mode. + + Some of the data passed to this template is known at runtime and not compile + time, so we need to craft the string at runtime with a JS template string. We + explicitly do not use Wasp mustaches here so we don't have to reason about two + different templating systems. + + For now, we don't serve any other static files in our routes, so all the + resources needed (CSS, images, etc.) must be inlined into the file. +*/ + +// The /* HTML */ comment is a hint to `prettier` to format this string as HTML. +export const makeWrongPortPage = ({ + appName, + frontendUrl, +}: { + appName: string; + frontendUrl: string; +}): string => /* HTML */ ` + + + + + + ${appName} API Server + + + + +
+
+

+ + + + + + Wasp +

+
+ +
+

${appName} API Server

+

+ The server is up and running. This is the backend part of your Wasp + application. +

+

+ If you want to visit your frontend application, go to this URL in + your browser: +

+ +

${frontendUrl}

+
+

+ + This message is shown because you are running the server in + development mode. In production, this route would not show + anything. + +

+
+
+ + +`; diff --git a/waspc/e2e-tests/snapshots/wasp-build-golden/wasp-app/.wasp/build/.waspchecksums b/waspc/e2e-tests/snapshots/wasp-build-golden/wasp-app/.wasp/build/.waspchecksums index 9d6b726ad1..beb851ceaf 100644 --- a/waspc/e2e-tests/snapshots/wasp-build-golden/wasp-app/.wasp/build/.waspchecksums +++ b/waspc/e2e-tests/snapshots/wasp-build-golden/wasp-app/.wasp/build/.waspchecksums @@ -522,7 +522,7 @@ "file", "server/src/routes/index.js" ], - "4e285034bd873a88d032d6331013191fea9899a6256b57838d25d94d272a5e75" + "635739ddcbd7f22b52dd5fa44f8ac5a8ebed914e64404701ae5b4796f44e97ac" ], [ [ diff --git a/waspc/e2e-tests/snapshots/wasp-build-golden/wasp-app/.wasp/build/server/src/routes/index.js b/waspc/e2e-tests/snapshots/wasp-build-golden/wasp-app/.wasp/build/server/src/routes/index.js index 49a94f5620..39db84e939 100644 --- a/waspc/e2e-tests/snapshots/wasp-build-golden/wasp-app/.wasp/build/server/src/routes/index.js +++ b/waspc/e2e-tests/snapshots/wasp-build-golden/wasp-app/.wasp/build/server/src/routes/index.js @@ -6,9 +6,11 @@ import { globalMiddlewareConfigForExpress } from '../middleware/index.js' const router = express.Router() const middleware = globalMiddlewareConfigForExpress() -router.get('/', middleware, function (_req, res) { - res.status(200).send(); -}) +router.get('/', middleware, + function (_req, res) { + res.status(200).send(); + } +) router.use('/operations', middleware, operations) diff --git a/waspc/e2e-tests/snapshots/wasp-compile-golden/snapshot-file-list.manifest b/waspc/e2e-tests/snapshots/wasp-compile-golden/snapshot-file-list.manifest index 72f763dcb6..d96f5a013a 100644 --- a/waspc/e2e-tests/snapshots/wasp-compile-golden/snapshot-file-list.manifest +++ b/waspc/e2e-tests/snapshots/wasp-compile-golden/snapshot-file-list.manifest @@ -296,6 +296,7 @@ wasp-app/.wasp/out/server/src/middleware/operations.ts wasp-app/.wasp/out/server/src/routes/index.js wasp-app/.wasp/out/server/src/routes/operations/index.js wasp-app/.wasp/out/server/src/server.ts +wasp-app/.wasp/out/server/src/views/wrong-port.ts wasp-app/.wasp/out/server/tsconfig.json wasp-app/.wasp/out/web-app/.env wasp-app/.wasp/out/web-app/.gitignore diff --git a/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/.waspchecksums b/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/.waspchecksums index d2aaa29632..dbf5437e83 100644 --- a/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/.waspchecksums +++ b/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/.waspchecksums @@ -522,7 +522,7 @@ "file", "server/src/routes/index.js" ], - "4e285034bd873a88d032d6331013191fea9899a6256b57838d25d94d272a5e75" + "e6d95c9a6fe716c22dec59fbb33e4072274a89f6c804f8d019a8752664622a12" ], [ [ @@ -538,6 +538,13 @@ ], "b58b023d27d41801136784aba57e2708eb1b47024adcc4fd179be1a10ff54899" ], + [ + [ + "file", + "server/src/views/wrong-port.ts" + ], + "cc8fc19e919c4d22ec6095a60446dd4f52dc864112e6b379ae35ec45c5b04b16" + ], [ [ "file", diff --git a/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/server/src/routes/index.js b/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/server/src/routes/index.js index 49a94f5620..dba1184720 100644 --- a/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/server/src/routes/index.js +++ b/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/server/src/routes/index.js @@ -1,14 +1,23 @@ import express from 'express' import operations from './operations/index.js' import { globalMiddlewareConfigForExpress } from '../middleware/index.js' +import { config } from 'wasp/server' +import { makeWrongPortPage } from '../views/wrong-port.js' const router = express.Router() const middleware = globalMiddlewareConfigForExpress() -router.get('/', middleware, function (_req, res) { - res.status(200).send(); -}) +router.get('/', middleware, + function (_req, res) { + const data = { + appName: "waspApp", + frontendUrl: config.frontendUrl + }; + const wrongPortPage = makeWrongPortPage(data); + res.status(200).type('html').send(wrongPortPage); + } +) router.use('/operations', middleware, operations) diff --git a/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts b/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts new file mode 100644 index 0000000000..c785cd4066 --- /dev/null +++ b/waspc/e2e-tests/snapshots/wasp-compile-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts @@ -0,0 +1,123 @@ +/* + This template gets rendered when you visit the root route on the server (i.e. + http://localhost:3001/) in development mode. + + Some of the data passed to this template is known at runtime and not compile + time, so we need to craft the string at runtime with a JS template string. We + explicitly do not use Wasp mustaches here so we don't have to reason about two + different templating systems. + + For now, we don't serve any other static files in our routes, so all the + resources needed (CSS, images, etc.) must be inlined into the file. +*/ + +// The /* HTML */ comment is a hint to `prettier` to format this string as HTML. +export const makeWrongPortPage = ({ + appName, + frontendUrl, +}: { + appName: string; + frontendUrl: string; +}): string => /* HTML */ ` + + + + + + ${appName} API Server + + + + +
+
+

+ + + + + + Wasp +

+
+ +
+

${appName} API Server

+

+ The server is up and running. This is the backend part of your Wasp + application. +

+

+ If you want to visit your frontend application, go to this URL in + your browser: +

+ +

${frontendUrl}

+
+

+ + This message is shown because you are running the server in + development mode. In production, this route would not show + anything. + +

+
+
+ + +`; diff --git a/waspc/e2e-tests/snapshots/wasp-migrate-golden/snapshot-file-list.manifest b/waspc/e2e-tests/snapshots/wasp-migrate-golden/snapshot-file-list.manifest index 5fe670b5ac..570565a610 100644 --- a/waspc/e2e-tests/snapshots/wasp-migrate-golden/snapshot-file-list.manifest +++ b/waspc/e2e-tests/snapshots/wasp-migrate-golden/snapshot-file-list.manifest @@ -307,6 +307,7 @@ wasp-app/.wasp/out/server/src/middleware/operations.ts wasp-app/.wasp/out/server/src/routes/index.js wasp-app/.wasp/out/server/src/routes/operations/index.js wasp-app/.wasp/out/server/src/server.ts +wasp-app/.wasp/out/server/src/views/wrong-port.ts wasp-app/.wasp/out/server/tsconfig.json wasp-app/.wasp/out/web-app/.env wasp-app/.wasp/out/web-app/.gitignore diff --git a/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/.waspchecksums b/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/.waspchecksums index 7bad83a53d..8db849fa72 100644 --- a/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/.waspchecksums +++ b/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/.waspchecksums @@ -529,7 +529,7 @@ "file", "server/src/routes/index.js" ], - "4e285034bd873a88d032d6331013191fea9899a6256b57838d25d94d272a5e75" + "e6d95c9a6fe716c22dec59fbb33e4072274a89f6c804f8d019a8752664622a12" ], [ [ @@ -545,6 +545,13 @@ ], "b58b023d27d41801136784aba57e2708eb1b47024adcc4fd179be1a10ff54899" ], + [ + [ + "file", + "server/src/views/wrong-port.ts" + ], + "cc8fc19e919c4d22ec6095a60446dd4f52dc864112e6b379ae35ec45c5b04b16" + ], [ [ "file", diff --git a/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/server/src/routes/index.js b/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/server/src/routes/index.js index 49a94f5620..dba1184720 100644 --- a/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/server/src/routes/index.js +++ b/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/server/src/routes/index.js @@ -1,14 +1,23 @@ import express from 'express' import operations from './operations/index.js' import { globalMiddlewareConfigForExpress } from '../middleware/index.js' +import { config } from 'wasp/server' +import { makeWrongPortPage } from '../views/wrong-port.js' const router = express.Router() const middleware = globalMiddlewareConfigForExpress() -router.get('/', middleware, function (_req, res) { - res.status(200).send(); -}) +router.get('/', middleware, + function (_req, res) { + const data = { + appName: "waspApp", + frontendUrl: config.frontendUrl + }; + const wrongPortPage = makeWrongPortPage(data); + res.status(200).type('html').send(wrongPortPage); + } +) router.use('/operations', middleware, operations) diff --git a/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts b/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts new file mode 100644 index 0000000000..c785cd4066 --- /dev/null +++ b/waspc/e2e-tests/snapshots/wasp-migrate-golden/wasp-app/.wasp/out/server/src/views/wrong-port.ts @@ -0,0 +1,123 @@ +/* + This template gets rendered when you visit the root route on the server (i.e. + http://localhost:3001/) in development mode. + + Some of the data passed to this template is known at runtime and not compile + time, so we need to craft the string at runtime with a JS template string. We + explicitly do not use Wasp mustaches here so we don't have to reason about two + different templating systems. + + For now, we don't serve any other static files in our routes, so all the + resources needed (CSS, images, etc.) must be inlined into the file. +*/ + +// The /* HTML */ comment is a hint to `prettier` to format this string as HTML. +export const makeWrongPortPage = ({ + appName, + frontendUrl, +}: { + appName: string; + frontendUrl: string; +}): string => /* HTML */ ` + + + + + + ${appName} API Server + + + + +
+
+

+ + + + + + Wasp +

+
+ +
+

${appName} API Server

+

+ The server is up and running. This is the backend part of your Wasp + application. +

+

+ If you want to visit your frontend application, go to this URL in + your browser: +

+ +

${frontendUrl}

+
+

+ + This message is shown because you are running the server in + development mode. In production, this route would not show + anything. + +

+
+
+ + +`; diff --git a/waspc/src/Wasp/Generator/ServerGenerator.hs b/waspc/src/Wasp/Generator/ServerGenerator.hs index 3f65dbb8f5..bfc737c49b 100644 --- a/waspc/src/Wasp/Generator/ServerGenerator.hs +++ b/waspc/src/Wasp/Generator/ServerGenerator.hs @@ -229,6 +229,7 @@ genSrcDir spec = genServerJs spec ] <++> genRoutesDir spec + <++> genViewsDir spec <++> genOperationsRoutes spec <++> genOperations spec <++> genAuth spec @@ -278,12 +279,24 @@ genRoutesIndex spec = "crudRouteInRootRouter" .= (CrudRoutes.crudRouteInRootRouter :: String), "isAuthEnabled" .= (isAuthEnabled spec :: Bool), "areThereAnyCustomApiRoutes" .= (not . null $ AS.getApis spec), - "areThereAnyCrudRoutes" .= (not . null $ AS.getCruds spec) + "areThereAnyCrudRoutes" .= (not . null $ AS.getCruds spec), + "isDevelopment" .= (not $ AS.isBuild spec :: Bool), + "appName" .= (fst $ getApp spec :: String) ] operationsRouteInRootRouter :: String operationsRouteInRootRouter = "operations" +genViewsDir :: AppSpec -> Generator [FileDraft] +genViewsDir spec + | AS.isBuild spec = return [] + | otherwise = + sequence + [ genFileCopy [relfile|views/wrong-port.ts|] + ] + where + genFileCopy = return . C.mkSrcTmplFd + genMiddleware :: AppSpec -> Generator [FileDraft] genMiddleware spec = sequence