0
Guys, I have a public folder with all the "public" files from my site html,css,js etc. And another folder called private with all the file private files connected with database and etc, which is a route only for me that I am admin can access it, and I want to know if I can block access to that route so in case an ordinary user tries to access this private route he can’t. So far I’ve managed to create middleware, but I don’t even know where to start, my app.js file is so far so far:
const express = require("express")
const handleBars = require("express-handlebars")
const bodyParser = require("body-parser")
const app = express()
const admin = require("admin")
const path = require("path")
//Configuções
app.use(bodyParser.urlencoded({extended: true})
app.use(bodyParser.json())
//Handlebars
app.engine('handlebars',handlebars({defaultLayout: 'main' }))
app.set('view-engine', 'handlebars')
//Public
app.use(express.static(path.join(__dirname + "public")))
app.use((req,res,next) => {
console.log("Middleware rodando")
next()
})
//Rotas
app.get("/", (req,res) => {
res.sendFile(__dirname + "/public/index.html")
})
app.use('/admin', admin)
const PORT = 3000
app.listen(PORT, () => {
console.log("Servidor rodando")
})
401 or 403, depending on the problem. Exceptions is not the best way to treat this type of error
– Costamilam