fairly new to Express, im trying to render simple ejs loading view, then do some asynchronized code, then load other view/redirect to other route and deal with the other view there. (thinking about the second option because i cannot change sended data after its been sent)
im getting [ERR_HTTP_HEADERS_SENT] for the redirect line, can i get some help with the situation?
const app = express();
const port = process.env.port || 2000
const puppeteer = require('puppeteer');
const fs = require('fs')
app.set('view engine', 'ejs');
app.get('/', async (req, res) => {
res.setHeader('Content-Type', 'text/html')
res.send(fs.readFileSync('./views/loading.ejs'))
if (fs.existsSync('./cookies.json')) {
//some async 10 sec code (puppeteer)
}
else{
//some async 10 sec code (puppeteer)
}
res.redirect(301,'/items')
})
app.get('/items', async (req, res) => {
res.setHeader('Content-Type', 'text/html')
res.send(fs.readFileSync('./views/items.ejs'))
})
app.listen(port)