Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2022
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //express
  2.  
  3. const express = require("express");
  4. const path = require("path");
  5. const bodyParser = require("body-parser");
  6. const v1DictionaryRouter = require("./src/back/v1/routes/dictionaryRoutes");
  7. const cors = require("cors");
  8.  
  9. const app = express();
  10. app.use(
  11.   cors({
  12.     origin: "*",
  13.   })
  14. );
  15.  
  16. const PORT = process.env.PORT || 8080;
  17.  
  18. app.use(bodyParser.json());
  19.  
  20. app.use(express.static("./src/front/dist"));
  21.  
  22. app.use("/api/v1/words", v1DictionaryRouter);
  23.  
  24. app.get("*", (req, res) => {
  25.   res.sendFile(path.resolve(__dirname + "/src/front/dist", "index.html"));
  26. });
  27.  
  28. app.listen(PORT, () => {
  29.   console.log(`API listening on port: :${PORT}`);
  30. });
  31.  
  32.  
  33. //react
  34.  
  35. import React from "react";
  36. import { BrowserRouter, Routes, Route } from "react-router-dom";
  37. import Layout from "../Layout/Layout";
  38. import Home from "../../pages/Home/Home";
  39. import Words from "../../pages/Words/Words";
  40. import BrowseWords from "../../pages/BrowseWords/BrowseWords";
  41.  
  42. const App = () => {
  43.   return (
  44.     <BrowserRouter>
  45.       <Routes>
  46.         <Route path="/" element={<Layout />}>
  47.           <Route index element={<Home />} />
  48.           <Route path="words" element={<Words />} />
  49.           <Route path="words/:id" element={<Alphabet1 />} /> // !! вложенность не работает !!
  50.           <Route path="browse" element={<BrowseWords />} />
  51.           <Route path="*" element={<NotFound />} />
  52.         </Route>
  53.       </Routes>
  54.     </BrowserRouter>
  55.   );
  56. };
  57.  
  58. const Alphabet1 = () => {
  59.   return <h1>Hello world</h1>;
  60. };
  61.  
  62. const NotFound = () => {
  63.   return <h2>Not found page</h2>;
  64. };
  65.  
  66. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement