diff --git a/core/prompts/architect/select_templates.prompt b/core/prompts/architect/select_templates.prompt index 9024cdbe0..e195fbcf1 100644 --- a/core/prompts/architect/select_templates.prompt +++ b/core/prompts/architect/select_templates.prompt @@ -7,19 +7,23 @@ Here is a high level description of "{{ state.branch.project.name }}": {{ state.specification.description }} ``` -You have an option to use project templates that implement standard boilerplate/scaffolding so you can start faster and be more productive. To be considered, a template must be compatible with the project requirements (it doesn't need to implement everything that will be used in the project, just a useful subset of needed technologies). You should pick one template that's the best match for this project. +You have an option to use project templates that implement standard boilerplate/scaffolding so you can start faster and be more productive. To be considered, a template must be compatible with the project requirements: +* if the project description has specific technology requirements, don't consider templates that choose different tech (eg. a different framework or library) +* to be considered, the template must use compatible technologies and implement a useful subset of required functionality -If no project templates are a good match, don't pick any! It's better to start from scratch than to use a template that is not a good fit for the project and then spend time reworking it to fit the requirements. +If no project templates are a good match, don't pick any! It's better to start from scratch than to use a template that is not a good fit for the project (for example, don't use a react frontend if a different framework or plain html/css is required) and then spend time reworking it to fit the requirements. If you do choose to pick a template, choose the one that's the best match for this project. Here are the available project templates: + {% for template in templates.values() %} ### {{ template.name }} ({{ template.stack }}) + {{ template.description }} Contains: {{ template.summary }} -{% endfor %} +{% endfor %} Output your response in a valid JSON format like in this example: ```json { diff --git a/core/templates/tree/react_express/api/app.js b/core/templates/tree/react_express/api/app.js index 7bb10278b..7c72a309a 100644 --- a/core/templates/tree/react_express/api/app.js +++ b/core/templates/tree/react_express/api/app.js @@ -1,4 +1,6 @@ import path from 'path'; +import { existsSync } from 'fs'; +import { fileURLToPath } from 'node:url'; import cors from 'cors'; import express from 'express'; @@ -9,6 +11,9 @@ import { authenticateWithToken } from './middlewares/authMiddleware.js'; {% endif %} import apiRoutes from './routes/index.js'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + // Set up Express app const app = express(); @@ -29,10 +34,22 @@ app.use(authenticateWithToken); app.use(apiRoutes); -app.use(express.static(path.join(import.meta.dirname, "..", "dist"))); +app.use(express.static(path.join(__dirname, "..", "dist"))); -// Assume all other routes are frontend and serve pre-built frontend from ../dist/ folder +// Assume all other routes are frontend app.get(/.*/, async (req, res) => { + // Try to serve pre-built frontend from ../dist/ folder + const clientBundlePath = path.join(__dirname, "..", "dist", "index.html"); + + if (!existsSync(clientBundlePath)) { + if (process.env.NODE_ENV === "development") { + // In development, we just want to redirect to the Vite dev server + return res.redirect("http://localhost:5173"); + } else { + // Looks like "npm run build:ui" wasn't run and the UI isn't built, show a nice error message instead + return res.status(404).send("Front-end not available."); + } + } res.sendFile(path.join(import.meta.dirname, "..", "dist", "index.html")); });