Create a test backend server with ExpressJs
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -28,3 +28,6 @@ coverage
|
|||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Build and package files/folders
|
||||||
|
build
|
||||||
11
software/backend/routes/routes.ts
Normal file
11
software/backend/routes/routes.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import express, { Request, Response, NextFunction } from 'express'
|
||||||
|
|
||||||
|
export const routes = app => {
|
||||||
|
var router = express.Router()
|
||||||
|
|
||||||
|
router.get("/", (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
res.send("Hello World from the backend!")
|
||||||
|
})
|
||||||
|
|
||||||
|
app.use("/api/", router)
|
||||||
|
}
|
||||||
21
software/backend/server.ts
Normal file
21
software/backend/server.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import express from 'express'
|
||||||
|
import cors from 'cors'
|
||||||
|
import bodyParser from 'body-parser'
|
||||||
|
import { routes } from './routes/routes'
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
const port = 3000
|
||||||
|
|
||||||
|
// Same origin access
|
||||||
|
app.use(cors())
|
||||||
|
|
||||||
|
// Process JSON parameter
|
||||||
|
app.use(bodyParser.json())
|
||||||
|
|
||||||
|
// Use the app routes
|
||||||
|
routes(app)
|
||||||
|
|
||||||
|
// Start server
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`Server is running and listening to port ${port}`)
|
||||||
|
})
|
||||||
1744
software/package-lock.json
generated
1744
software/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,22 +1,37 @@
|
|||||||
{
|
{
|
||||||
"name": "software",
|
"name": "hackmycart",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"dev-server": "concurrently \"nodemon\" \"wait-on http://localhost:3000/api/ && vite\""
|
||||||
|
},
|
||||||
|
"nodemonConfig": {
|
||||||
|
"watch": [
|
||||||
|
"backend"
|
||||||
|
],
|
||||||
|
"exec": "tsc && node ./build/dist/server.js",
|
||||||
|
"ext": "ts, js, json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mdi/font": "^7.4.47",
|
"@mdi/font": "^7.4.47",
|
||||||
"@types/node": "^22.5.2",
|
"axios": "^1.7.7",
|
||||||
"typescript": "^5.5.4",
|
"body-parser": "^1.20.2",
|
||||||
|
"concurrently": "^8.2.2",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.19.2",
|
||||||
"vue": "^3.4.29",
|
"vue": "^3.4.29",
|
||||||
"vuetify": "^3.7.1"
|
"vuetify": "^3.7.1",
|
||||||
|
"wait-on": "^8.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/cors": "^2.8.17",
|
||||||
|
"@types/express": "^4.17.21",
|
||||||
|
"@types/node": "^22.5.2",
|
||||||
"@vitejs/plugin-vue": "^5.0.5",
|
"@vitejs/plugin-vue": "^5.0.5",
|
||||||
|
"nodemon": "^3.1.4",
|
||||||
"vite": "^5.3.1"
|
"vite": "^5.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
const showDrawer = ref(true)
|
const showDrawer = ref(true)
|
||||||
|
const testResponse = ref("")
|
||||||
|
|
||||||
|
|
||||||
|
axios.get('http://127.0.0.1:3000/api')
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response)
|
||||||
|
testResponse.value = response.data
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -17,6 +26,7 @@ const showDrawer = ref(true)
|
|||||||
</v-navigation-drawer>
|
</v-navigation-drawer>
|
||||||
|
|
||||||
<v-main>
|
<v-main>
|
||||||
|
{{ testResponse }}
|
||||||
<!-- todo -->
|
<!-- todo -->
|
||||||
</v-main>
|
</v-main>
|
||||||
</v-app>
|
</v-app>
|
||||||
|
|||||||
@@ -10,5 +10,8 @@
|
|||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"],
|
||||||
|
"include": [
|
||||||
|
"backend/**/*.ts",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user