parent
6692c96835
commit
b89953dbe8
9 changed files with 1689 additions and 0 deletions
@ -0,0 +1,5 @@ |
||||
# dependencies |
||||
/node_modules |
||||
|
||||
# production |
||||
striker-ui-api |
@ -0,0 +1,6 @@ |
||||
{ |
||||
"endOfLine": "lf", |
||||
"singleQuote": true, |
||||
"tabWidth": 2, |
||||
"trailingComma": "all" |
||||
} |
@ -0,0 +1,14 @@ |
||||
const express = require('express'); |
||||
const path = require('path'); |
||||
|
||||
const API_ROOT_PATH = require('./lib/consts/API_ROOT_PATH'); |
||||
|
||||
const echoRoute = require('./routes/echo'); |
||||
|
||||
const app = express(); |
||||
|
||||
app.use(express.json()); |
||||
|
||||
app.use(path.join(API_ROOT_PATH, 'echo'), echoRoute); |
||||
|
||||
module.exports = app; |
@ -0,0 +1,7 @@ |
||||
const app = require('./app'); |
||||
|
||||
const SERVER_PORT = require('./lib/consts/SERVER_PORT'); |
||||
|
||||
app.listen(SERVER_PORT, () => { |
||||
console.log(`Listening on localhost:${SERVER_PORT}.`); |
||||
}); |
@ -0,0 +1,3 @@ |
||||
const API_ROOT_PATH = '/api'; |
||||
|
||||
module.exports = API_ROOT_PATH; |
@ -0,0 +1,3 @@ |
||||
const SERVER_PORT = process.env.SERVER_PORT ?? 8080; |
||||
|
||||
module.exports = SERVER_PORT; |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,18 @@ |
||||
{ |
||||
"name": "striker-ui-api", |
||||
"version": "0.1.0", |
||||
"description": "API for striker-ui", |
||||
"scripts": { |
||||
"build": "pkg --compress GZip --output striker-ui-api --targets node14-linux index.js", |
||||
"clean": "rm -f striker-ui-api", |
||||
"rebuild": "npm run clean && npm run build", |
||||
"start": "npm run build && ./striker-ui-api" |
||||
}, |
||||
"dependencies": { |
||||
"express": "^4.17.1" |
||||
}, |
||||
"devDependencies": { |
||||
"pkg": "^5.5.1", |
||||
"prettier": "^2.5.0" |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
const express = require('express'); |
||||
|
||||
const router = express.Router(); |
||||
|
||||
router |
||||
.get('/', (request, response) => { |
||||
response.status(200).send({ message: 'Empty echo.' }); |
||||
}) |
||||
.post('/', (request, response) => { |
||||
console.log('echo:post', JSON.stringify(request.body, undefined, 2)); |
||||
|
||||
const message = request.body.message ?? 'No message.'; |
||||
|
||||
response.status(200).send({ message }); |
||||
}); |
||||
|
||||
module.exports = router; |
Loading…
Reference in new issue