Failed to load resource: net::ERR_CONNECTION_RESET doesn't see static data

24 Views Asked by At

strange error when deleting and adding:

Failed to load resource: net::ERR_CONNECTION_RESET style/custom.css:1

all static files are not loaded from time to time after delate and post method server code:

const express = require('express');
const path = require('path');
const app = express();
const DB = require('./DB.js');
const PORT = 3000;

app.set('veiw engine','ejs');

/*logic error не проработан*/

const CreatePath = (file) => path.resolve(__dirname,'views',file + '.ejs');

app.use('/style',express.static('style'));
app.use('/script', express.static('script'));
app.use('/img', express.static('img'));

app.use(express.urlencoded({extended:false}));

app.get('/', (req, res) => {
    res.render(CreatePath('index'));
});

app.get('/chart', (req, res) => {
    res.render(CreatePath('chart'));
});

app.get('/students', (req, res) => {
    res.render(CreatePath('students'));
});

app.get('/registration', (req, res) => {
    const date = DB.ShowAll(); 
    res.render(CreatePath('registration'),{date});
});
app.delete('/registration/:id',(req,res)=>{
    console.log(req.params.id);
    DB.DeleteById(req.params.id).then((result)=>{
        res.sendStatus(200);
    });
})

app.get('/addstudent', (req, res) => {
    res.render(CreatePath('addstudent'));
});

app.post('/addstudent',(req,res)=>{
    DB.WriteDate(req.body);
    res.render(CreatePath('index'));
});

app.listen(PORT,'localhost',()=>{
    console.log('start!');
});

why is this strange because in windows everything worked correctly when switching to linux (debian) it all started

in the beginning it was:

app.use(express.static('style'));
app.use(express.static('script'));
app.use(express.static('img'));

but changing the URL didn't help

  • tried through the full path
app.use('/style',express.static(__dirname + '/style'));
app.use('/script', express.static(__dirname + '/script'));
app.use('/img', express.static(__dirname + '/img'));
0

There are 0 best solutions below