Skip to content
Snippets Groups Projects
Commit 125bb28a authored by Leander Tolksdorf's avatar Leander Tolksdorf
Browse files

Pretty big commit. What I've done:

- Split server and client into two separate packages.
- Update README with info on how to start dev server locally
- Client
	- Update react-router-dom to v6
	- Separate page components from UI components
	- Add "proxy" field to package.json for proxying api requests to the backend server
- Server
	- Update path of static file serving to new client directory
	- Update scripts
parent 77d11f52
No related branches found
No related tags found
No related merge requests found
File moved
File moved
File moved
File moved
import "dotenv/config";
import express from "express";
import apiRouter from "./routes";
import path from "path";
import dbInit from "./db/db_init";
let init = async () => {
await dbInit();
const app = express();
app.use(express.static(path.join(__dirname, "../../client/build")));
app.use(express.json());
app.use(apiRouter);
app.get("/", function (req, res) {
res.sendFile(
path.join(__dirname, "../../client/build/index.html"),
function (err) {
if (err) {
res.status(500).send(err);
}
}
);
});
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Server listening on port: ${port}`));
};
init().then(() => {});
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
]
}
import * as React from "react";
import { Link } from "react-router-dom";
function Home() {
return (
<div>
<Link to={"/qr/testId"}>QR</Link>
</div>
);
}
export default Home;
import * as React from "react";
import { render } from "react-dom";
import AppRouter from "./router";
import "./css/app";
function App() {
return <AppRouter />;
}
render(<App />, document.getElementById("app"));
import * as React from "react";
import Header from "./components/header";
import CreateLogEntry from "./components/createLogEntry";
import Home from "./components/home";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import VehicleTypes from "./components/vehicleTypes";
function AppRouter() {
return (
<BrowserRouter>
<Header />
<div className="mainView">
<Switch>
<Route path={["/", "/home"]} component={Home} exact />
<Route path="/qr/:vehicleId" component={CreateLogEntry} />
<Route path="/vehicleTypes" component={VehicleTypes} exact />
<Route path="/login" exact />
<Route />
</Switch>
</div>
</BrowserRouter>
);
}
export default AppRouter;
import * as express from 'express';
import apiRouter from './routes';
import * as path from 'path';
import dbInit from "./db/db_init";
let init = async ()=>{
await dbInit();
const app = express();
app.use(express.static('public'));
app.use(express.json());
app.use(apiRouter);
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname, '/../public/index.html'), function(err) {
if (err) {
res.status(500).send(err)
}
})
})
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Server listening on port: ${port}`));
}
init().then(() => {})
{
"compilerOptions": {
"outDir": "./public/js/",
"noImplicitAny": true,
"module": "es6",
"moduleResolution": "node",
"target": "es5",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"lib":[
"es2015", "dom"
]
},
"include": [
"src/client/**/*"
],
"exclude": [
"node_modules"
]
}
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "commonjs",
"target": "ES6",
"allowSyntheticDefaultImports": true,
"lib": [
"es2017"
],
"types": [
"node", "express"
]
},
"include": [
"src/server/**/*"
],
"exclude": [
"node_modules"
]
}
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const ESLintPlugin = require('eslint-webpack-plugin');
const serverConfig = {
mode: process.env.NODE_ENV || 'development',
entry: './src/server/server.ts',
module: {
rules: [
{
test: /\.ts?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
configFile: 'tsconfig.server.json'
}
}
]
},
resolve: {
extensions: ['.ts', '.js']
},
output: {
filename: 'server.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [new ESLintPlugin({fix: true, files: "./src/server"})],
target: 'node',
node: {
__dirname: false
},
externals: [nodeExternals()]
};
const clientConfig = {
mode: process.env.NODE_ENV || 'development',
entry: './src/client/index.tsx',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
configFile: 'tsconfig.client.json'
}
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.css', '.scss']
},
plugins: [new ESLintPlugin({fix: true, files: "./src/client"})],
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'public/js'),
publicPath: '/'
}
};
module.exports = [serverConfig, clientConfig];
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment