Created
December 12, 2023 22:00
-
-
Save fgp555/ebdd37bd48c83f9398cccdde4bd2872a to your computer and use it in GitHub Desktop.
09_express_mvc_jonmircha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from "express"; | |
import path from "path"; | |
import cors from "cors"; | |
import helmet from "helmet"; | |
import morgan from "morgan"; | |
import taskController from "./controllers/taskController.js"; | |
import errorController from "./controllers/errorController.js"; | |
// const __dirname = path.dirname(new URL(import.meta.url).pathname); | |
import { fileURLToPath } from "url"; | |
const __dirname = fileURLToPath(new URL(".", import.meta.url)); | |
const app = express(); | |
const port = 3000; | |
app.use(cors()); | |
app.use(helmet()); | |
app.use(morgan("dev")); | |
app.set("views", path.join(__dirname, "views")); | |
app.set("view engine", "pug"); | |
app.use(express.static(path.join(__dirname, "public"))); | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: false })); | |
app.get("/", taskController.getAllTasks); | |
app.get("/add", taskController.getAddTaskForm); | |
app.post("/add", taskController.addTask); | |
app.get("/edit/:id", taskController.getEditTaskForm); | |
app.post("/edit/:id", taskController.editTask); | |
app.get("/complete/:id", taskController.completeTask); | |
app.get("/uncomplete/:id", taskController.uncompleteTask); | |
app.get("/delete/:id", taskController.deleteTask); | |
app.use(errorController.error404); | |
app.listen(port, () => { | |
console.log(`La aplicación está funcionando en http://localhost:${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment