Create a test backend server with ExpressJs
This commit is contained in:
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}`)
|
||||
})
|
||||
Reference in New Issue
Block a user