Skip to content

Commit

Permalink
Merge pull request #1079 from Pythagora-io/template-fixes
Browse files Browse the repository at this point in the history
Template fixes
  • Loading branch information
LeonOstrez authored Aug 5, 2024
2 parents 98de63e + 560a2e6 commit b33282f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions core/agents/spec_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ async def initialize_spec(self) -> AgentResponse:
if len(user_description) < ANALYZE_THRESHOLD and complexity != Complexity.SIMPLE:
initial_spec = await self.analyze_spec(user_description)
reviewed_spec = await self.review_spec(desc=user_description, spec=initial_spec)
else:
initial_spec = reviewed_spec = user_description

self.next_state.specification = self.current_state.specification.clone()
self.next_state.specification.original_description = user_description
Expand Down
7 changes: 3 additions & 4 deletions core/templates/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from .javascript_react import JavascriptReactProjectTemplate
from .node_express_mongoose import NodeExpressMongooseProjectTemplate

# from .react_express import ReactExpressProjectTemplate
from .react_express import ReactExpressProjectTemplate

log = get_logger(__name__)

Expand All @@ -15,11 +14,11 @@ class ProjectTemplateEnum(str, Enum):

JAVASCRIPT_REACT = JavascriptReactProjectTemplate.name
NODE_EXPRESS_MONGOOSE = NodeExpressMongooseProjectTemplate.name
# REACT_EXPRESS = ReactExpressProjectTemplate.name
REACT_EXPRESS = ReactExpressProjectTemplate.name


PROJECT_TEMPLATES = {
JavascriptReactProjectTemplate.name: JavascriptReactProjectTemplate,
NodeExpressMongooseProjectTemplate.name: NodeExpressMongooseProjectTemplate,
# ReactExpressProjectTemplate.name: ReactExpressProjectTemplate,
ReactExpressProjectTemplate.name: ReactExpressProjectTemplate,
}
2 changes: 1 addition & 1 deletion core/templates/tree/react_express/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ app.use(cors());
{% if options.auth %}

// Authentication routes
app.use(authRoutes);
app.use(authenticateWithToken);
app.use(authRoutes);
{% endif %}

app.use(apiRoutes);
Expand Down
4 changes: 4 additions & 0 deletions core/templates/tree/react_express/api/routes/authRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ router.post('/api/auth/password', requireUser, async (req, res) => {
res.status(204).send();
});

router.get('/api/auth/me', requireUser, async (req, res) => {
return res.status(200).json(req.user);
});

export default router;
12 changes: 12 additions & 0 deletions core/templates/tree/react_express/ui/main.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% if options.auth %}
import axios from 'axios'
{% endif %}
import React from 'react'
import ReactDOM from 'react-dom/client'
import { createBrowserRouter, RouterProvider, useLocation } from "react-router-dom"
Expand All @@ -9,6 +12,15 @@ import Home from './pages/Home.jsx'
{% if options.auth %}
import Register from './pages/Register.jsx'
import Login from './pages/Login.jsx'

// Add auth token to every API request if we have it
axios.interceptors.request.use(config => {
const token = localStorage.getItem("token");
if (token && !config.headers.Authorization) {
config.headers.Authorization = `Token ${token}`
}
return config
})
{% endif %}

function PageNotFound() {
Expand Down

0 comments on commit b33282f

Please sign in to comment.