Commit 53ba8979 authored by Isuru Liyanage's avatar Isuru Liyanage
Browse files

add router to support base URL

parent 3072b3f5
This diff is collapsed.
......@@ -34,7 +34,7 @@
},
"devDependencies": {
"bufferutil": "^4.0.2",
"canvas": "^2.6.1",
"canvas": "^2.7.0",
"jest": "^26.6.0",
"nodemon": "^2.0.6",
"ts-node": "^9.1.0",
......
......@@ -8,9 +8,11 @@ const argv = require("yargs").argv;
const npid = require("npid");
const app = express();
const router = express.Router()
const port = process.env.PORT || 3020;
const basePath = process.env.VALIDATOR_BASE_URL || '/';
app.use(express.static('src/views'));
router.use(express.static('src/views'));
app.use(bodyParser.json());
......@@ -32,7 +34,7 @@ app.use(function(err, req, res, next) {
}
});
app.post("/validate", (req, res) => {
router.post("/validate", (req, res) => {
logger.log("debug", "Received POST request.");
var inputSchema = req.body.schema;
......@@ -54,7 +56,7 @@ app.post("/validate", (req, res) => {
}
});
app.get("/validate", (req, res) => {
router.get("/validate", (req, res) => {
logger.log("silly", "Received GET request.");
res.send({
......@@ -66,6 +68,8 @@ app.get("/validate", (req, res) => {
});
});
app.use(basePath, router);
app.listen(port, () => {
logger.log("info", ` -- Started server on port ${port} --`);
if(argv.logPath) { logger.log("info", ` --> Log output: ${argv.logPath}`); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment