0

При открытии приложения все ок, далее перехожу на любую страницу и сначала (на секунду) все рендерится, потом все падает с ошибкой. Локально все работает. Для сервера я использую json-server

GET https://clothes-shop-copy.herokuapp.com/catalog/womancollection/obuv/113458 404 (Not Found)

 server.js

import pkg from 'json-server';
import path from 'path'; 
import { fileURLToPath } from 'url';
import express from 'express';


const { create,  router: _router,  defaults , rewriter } = pkg;
const dirname = path.dirname;
const __dirname = dirname(fileURLToPath(import.meta.url));
const server = create();
const router = _router('users.json');
const middlewares = defaults({
  static: './build'
});
const PORT = process.env.PORT || 3001;
server.use(middlewares);
server.use(rewriter({
  '/api/*': '/$1',
}))
server.use(router);

server.use(express.static(path.join(__dirname, 'build')));

server.get('/*', function (req, res) {
    res.sendFile(path.join(__dirname, 'build' , 'index.html'));
});
console.log(__dirname);

server.listen(PORT, () => {
  console.log('Server is running');
});

Также у меня есть файл static.json

{
"root": "build/",
"clean_urls": false,
"routes": {
  "/**": "index.html"
}

}

Прикладываю HEROKU LOGS

2022-05-13T14:51:20.903568+00:00 app[web.1]: [0mGET /users/164f6f53-d2db-4708-91b7-9505b580c3a2 [36m304[0m 2.971 ms - -[0m
2022-05-13T14:51:21.043508+00:00 app[web.1]: [0mGET /womancollection [32m200[0m 3.729 ms - -[0m
2022-05-13T14:51:23.183831+00:00 app[web.1]: [0mGET /womancollection [36m304[0m 4.233 ms - -[0m
2022-05-13T14:51:23.194414+00:00 app[web.1]: [0mGET /users/164f6f53-d2db-4708-91b7-9505b580c3a2 [36m304[0m 2.939 ms - -[0m
2022-05-13T14:51:23.811276+00:00 app[web.1]: [0mGET /womancollection [32m200[0m 4.597 ms - -[0m
2022-05-13T14:51:23.812136+00:00 app[web.1]: [0mGET /users/164f6f53-d2db-4708-91b7-9505b580c3a2 [32m200[0m 4.760 ms - -[0m
2022-05-13T14:51:23.954422+00:00 app[web.1]: [0mGET /users/164f6f53-d2db-4708-91b7-9505b580c3a2 [36m304[0m 2.932 ms - -[0m
2022-05-13T14:53:50.583997+00:00 app[web.1]: [0mGET /users/164f6f53-d2db-4708-91b7-9505b580c3a2 [36m304[0m 2.330 ms - -[0m
2022-05-13T14:53:50.586460+00:00 app[web.1]: [0mGET /womancollection [36m304[0m 4.184 ms - -[0m
2022-05-13T14:53:52.637884+00:00 app[web.1]: [0mGET /users/164f6f53-d2db-4708-91b7-9505b580c3a2 [36m304[0m 2.797 ms - -[0m
1
  • проблемы с путями наверное 13 мая 2022 в 17:47

1 ответ 1

0

Спустя три дня и перепробовав все возможные варианты , проблему удалось решить, сменив BrowserRouter на HashRouter при построении путей. Надеюсь этот ответ будет полезен всем, кто столкнется с этой проблемой.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.