feat: add API skeleton for striker-ui

main
Tsu-ba-me 3 years ago
parent 6692c96835
commit b89953dbe8
  1. 5
      striker-ui-api/.gitignore
  2. 6
      striker-ui-api/.prettierrc.json
  3. 14
      striker-ui-api/app.js
  4. 7
      striker-ui-api/index.js
  5. 3
      striker-ui-api/lib/consts/API_ROOT_PATH.js
  6. 3
      striker-ui-api/lib/consts/SERVER_PORT.js
  7. 1616
      striker-ui-api/package-lock.json
  8. 18
      striker-ui-api/package.json
  9. 17
      striker-ui-api/routes/echo.js

@ -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…
Cancel
Save