improved api
This commit is contained in:
parent
3be0cc8380
commit
f3f0945ccc
6 changed files with 174 additions and 7 deletions
|
|
@ -10,14 +10,14 @@ const port = 3000
|
|||
|
||||
app.use(helmet())
|
||||
|
||||
// init database connection
|
||||
const pgp = pgPromise({});
|
||||
const db = pgp('postgres://postgres:postgres@localhost:5432/rr')
|
||||
|
||||
// configure & use logger
|
||||
let morganFormatted = morgan('[:date[iso]] :method :url - :status')
|
||||
app.use(morganFormatted);
|
||||
|
||||
// init database connection
|
||||
const pgp = pgPromise({});
|
||||
const db = pgp('postgres://postgres:postgres@localhost:5432/rr')
|
||||
|
||||
|
||||
app.get('/highscore', async (req, res) => {
|
||||
let data = await db.any(
|
||||
|
|
@ -27,5 +27,5 @@ app.get('/highscore', async (req, res) => {
|
|||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`)
|
||||
morganFormatted.log(`Server started at http://localhost:3000`);
|
||||
})
|
||||
16
backend/api/src/exampleEndpoints.ts
Normal file
16
backend/api/src/exampleEndpoints.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import * as express from 'express';
|
||||
import * as bodyParser from "body-parser";
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.use(bodyParser.json())
|
||||
|
||||
router.get('/helloworld', (req, res) => {
|
||||
res.json({message: "Hello World!"})
|
||||
})
|
||||
|
||||
router.post('/echo', (req, res) => {
|
||||
res.json(req.body)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
Loading…
Add table
Add a link
Reference in a new issue