serve react page

This commit is contained in:
Erik 2022-03-20 18:11:20 +02:00
parent e49a467622
commit 52724fab80
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589

View File

@ -0,0 +1,38 @@
const { Endpoint } = require('../interfaces');
const path = require('path');
const express = require('express');
class Home extends Endpoint {
constructor(client, opts) {
super(client, {
name: 'home',
path: '(/*)?',
...opts
});
this.methods = [
['get', this.get.bind(this)]
];
this.mediaDir = path.join(this.client.baseDirectory, 'media');
const assets = path.resolve(this.client.baseDirectory, '../client/build/static');
const manifest = path.resolve(this.client.baseDirectory, '../client/build/manifest.json');
this.client.app.use('/static', express.static(assets));
this.client.app.use('/manifest.json', express.static(manifest));
this.init();
}
async get(req, res) {
const home = path.resolve(this.client.baseDirectory, '../client/build/index.html');
res.sendFile(home);
}
}
module.exports = Home;