2017-11-27 07:15:09 +01:00
|
|
|
import express from 'express';
|
|
|
|
import bodyParser from 'body-parser';
|
|
|
|
|
2019-09-26 18:22:14 +02:00
|
|
|
/**
|
|
|
|
* Simple Server
|
|
|
|
*
|
2019-10-02 21:14:19 +02:00
|
|
|
* A empty express server with the objective to emumate any external API.
|
2019-09-26 18:22:14 +02:00
|
|
|
*
|
|
|
|
* eg: test/functional/tags/tags.ts
|
|
|
|
*
|
|
|
|
* express.get('/testexp_tags', function(req, res) {
|
|
|
|
let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags');
|
|
|
|
res.send(JSON.parse(f));
|
|
|
|
});
|
|
|
|
*
|
|
|
|
* or at test/functional/package/gzip.ts
|
|
|
|
*/
|
2017-12-02 09:52:40 +01:00
|
|
|
export default class ExpressServer {
|
2019-09-26 18:22:14 +02:00
|
|
|
private app: any;
|
|
|
|
private server: any;
|
2017-11-27 07:15:09 +01:00
|
|
|
|
2019-09-26 18:22:14 +02:00
|
|
|
public constructor() {
|
2017-12-03 22:23:06 +01:00
|
|
|
this.app = express();
|
|
|
|
}
|
2017-12-02 09:52:40 +01:00
|
|
|
|
2019-09-26 18:22:14 +02:00
|
|
|
public start(port: number): Promise<ExpressServer> {
|
2018-06-14 07:25:09 +02:00
|
|
|
return new Promise((resolve) => {
|
2017-12-03 22:23:06 +01:00
|
|
|
this.app.use(bodyParser.json());
|
|
|
|
this.app.use(bodyParser.urlencoded({
|
|
|
|
extended: true
|
|
|
|
}));
|
2017-11-27 07:15:09 +01:00
|
|
|
|
2019-09-26 18:22:14 +02:00
|
|
|
this.server = this.app.listen(port, () => resolve(this));
|
2017-12-03 22:23:06 +01:00
|
|
|
});
|
|
|
|
}
|
2017-11-27 07:15:09 +01:00
|
|
|
}
|