-
Notifications
You must be signed in to change notification settings - Fork 66
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
d03a82f
commit c21df61
Showing
8 changed files
with
2,821 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist | ||
node_modules | ||
.DS_Store |
Large diffs are not rendered by default.
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,30 @@ | ||
{ | ||
"name": "nodejs-express-axios-starter", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "tsc && node dist/app.js", | ||
"dev": "nodemon src/app.ts", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "Shaun Ganley <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^1.6.8", | ||
"body-parser": "^1.20.2", | ||
"express": "^4.19.2", | ||
"express-session": "^1.18.0", | ||
"nunjucks": "^3.2.4" | ||
}, | ||
"devDependencies": { | ||
"@types/axios": "^0.14.0", | ||
"@types/express": "^4.17.21", | ||
"@types/express-session": "^1.18.0", | ||
"@types/node": "^20.11.30", | ||
"@types/nunjucks": "^3.2.6", | ||
"nodemon": "^3.1.0", | ||
"ts-node": "^10.9.2" | ||
} | ||
} |
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,32 @@ | ||
import express from "express"; | ||
import nunjucks from "nunjucks"; | ||
import bodyParser from "body-parser"; | ||
import session from "express-session"; | ||
|
||
import { getAllDatabases } from "./controllers/TestController"; | ||
|
||
const app = express(); | ||
|
||
const env = nunjucks.configure('views', { | ||
autoescape: true, | ||
express: app | ||
}); | ||
|
||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded({ | ||
extended: true | ||
})) | ||
|
||
app.use(session({ secret: 'SUPER_SECRET', cookie: { maxAge: 28800000 }})); | ||
|
||
declare module "express-session" { | ||
interface SessionData { | ||
token: string; | ||
} | ||
} | ||
|
||
app.listen(3000, () => { | ||
console.log('Server started on port 3000'); | ||
}); | ||
|
||
app.get('/', getAllDatabases); |
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,6 @@ | ||
import express from "express"; | ||
import { getDatabases } from "../services/TestService" | ||
|
||
export const getAllDatabases = async (req: express.Request, res: express.Response): Promise<void> => { | ||
res.render('databaseList.html', { databases: await getDatabases() }); | ||
} |
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,12 @@ | ||
import axios, { AxiosResponse } from "axios"; | ||
|
||
export const getDatabases = async (): Promise<string[]> => { | ||
try { | ||
const response: AxiosResponse = await axios.get("http://localhost:8080/api/test"); | ||
|
||
return response.data; | ||
} catch (e) { | ||
console.log(e); | ||
throw new Error('Failed to get databases'); | ||
} | ||
} |
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,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"target": "es6", | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "./dist" | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Database List</title> | ||
</head> | ||
<body> | ||
<h1>Database List</h1> | ||
<ul> | ||
{% for name in databases %} | ||
<li>{{ name }}</li> | ||
{% endfor %} | ||
</ul> | ||
</body> | ||
</html> |