-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a24fdfa
commit 6560c79
Showing
23 changed files
with
1,584 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Possible Actions | ||
// Index | Show | Create | Store | Edit | Update | Destroy | ||
|
||
export default class HomeController { | ||
index(req, res) { | ||
res.render("index", { | ||
title: "Home", | ||
author: "barcellos-pedro", | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Possible Actions | ||
// Index | Show | Create | Store | Edit | Update | Destroy | ||
|
||
export default class TodosController { | ||
index(req, res) { | ||
res.render("todos/index", { | ||
title: "Todos - Home", | ||
tasks: [], | ||
}) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import hanblebars from "express-handlebars" | ||
|
||
const extname = ".hbs" | ||
|
||
const { engine } = hanblebars.create({ extname }) | ||
|
||
export default function setupViewEngine(setupFn) { | ||
setupFn(extname, engine) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,49 @@ | ||
import express from "express" | ||
import config from "../config/config.js" | ||
import setupViewEngine from "./View.js" | ||
import Router from "../routes.js" | ||
|
||
export default class App { | ||
#instance | ||
|
||
constructor() { | ||
console.log("[Thane Stack] ☄️") | ||
|
||
this.#instance = express() | ||
this.port = config({ key: "port", defaultValue: 8080 }) | ||
|
||
this.start() | ||
this.app = express() | ||
this.router = Router | ||
this.#bootstrap() | ||
} | ||
|
||
static new() { | ||
return new this() | ||
} | ||
|
||
get app() { | ||
return this.#instance | ||
start(port = 800) { | ||
this.port = config({ key: "port", defaultValue: port }) | ||
this.app.listen(this.port, () => this.startLog()) | ||
} | ||
|
||
start() { | ||
this.app.listen(this.port, () => | ||
console.log(`⚡Application running on http://localhost:${this.port}`) | ||
) | ||
startLog() { | ||
console.log(`⚡Application running on http://localhost:${this.port}`) | ||
} | ||
} | ||
|
||
// TODO: Register Middlewares | ||
|
||
// app.use(express.static("public")); | ||
// app.use(express.json()); | ||
// app.use(express.urlencoded({ extended: false })); | ||
|
||
// ---------------------------------------------- | ||
|
||
// TODO: Set View Engine (Handlebars) | ||
#initRoutes() { | ||
this.router.registerRoutes(this.app) | ||
} | ||
|
||
// import hanblebars from "express-handlebars"; | ||
#initMiddlewares() { | ||
this.app.use(express.static("public")) | ||
this.app.use(express.json()) | ||
this.app.use(express.urlencoded({ extended: false })) | ||
} | ||
|
||
// const hbs = hanblebars.create({ | ||
// extname: ".hbs", | ||
// helpers, | ||
// }); | ||
#initViews() { | ||
setupViewEngine((extname, engine) => { | ||
this.app.engine(extname, engine) | ||
this.app.set("view engine", extname) | ||
this.app.set("views", "views") | ||
}) | ||
} | ||
|
||
// app.engine(".hbs", hbs.engine); | ||
// app.set("view engine", ".hbs"); | ||
// app.set("views", "views"); | ||
#bootstrap() { | ||
this.#initMiddlewares() | ||
this.#initViews() | ||
this.#initRoutes() | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
// Router | ||
export default class Router { | ||
routes = [] | ||
|
||
// import express from "express"; | ||
static init() { | ||
return new this() | ||
} | ||
|
||
// const router = express.Router(); | ||
get(path, [routeController, action]) { | ||
this.#addRoute({ | ||
method: "GET", | ||
controller: routeController, | ||
path, | ||
action, | ||
}) | ||
|
||
// router.get("/", (req, res) => { | ||
// res.render("index", {}); | ||
// }); | ||
return this | ||
} | ||
|
||
class Router { | ||
static get(path, props){ | ||
const [controller, method] = props | ||
registerRoutes(app) { | ||
this.routes.forEach(({ path, action, controller }) => { | ||
const routeController = new controller() | ||
const handler = routeController[action] | ||
app.use(path, handler) | ||
}) | ||
} | ||
|
||
} | ||
} | ||
#addRoute(routeProps) { | ||
this.routes.push({ ...routeProps, middleware: "none" }) | ||
console.log("[Routes]\n", this.routes) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import App from "./core/app.js" | ||
|
||
App.new().start() |
Oops, something went wrong.