diff --git a/README.md b/README.md index 59fb7b5..cb0322e 100644 --- a/README.md +++ b/README.md @@ -64,23 +64,24 @@ A basic web app client in the **/client** directory will show basic API usage an ## Usage 1. Navigate to the `/server` directory. -2. Generate the API documentation. +2. Create a default Firebase Auth user. +`npm run seed` +3. Generate the API documentation. `npm run gen:docs` -3. Run the app: +4. Run the app: - (development mode) `npm run dev` - (production mode) `npm start` -4. Read the API documentation and usage examples guide of available CRUD API endpoints on: +5. Read the API documentation and usage examples guide of available CRUD API endpoints on: `http://localhost:3001/docs` -5. Try to log-in to the `/client` app using the default superadmin seeded user: +6. Try to log-in to the `/client` app using the default superadmin seeded user from step no. 2: ``` username: superadmin@gmail.com password: 123456789 ``` -6. Use the CRUD API endpoints to create/update/delete or view Firebase Auth users using Postman, curl, or other http clients. +7. Use the CRUD API endpoints to create/update/delete or view Firebase Auth users using Postman, curl, or other http clients. - Try signing in these users to the `/client` app. - ## Available Scripts - server The npm scripts listed below are available under the **/server** directory. @@ -108,5 +109,16 @@ password: 123456789 account_level: 1 ``` +### `npm run copyclient` + +Copies the built `/client` website from `/client/build` to the server's root directory. + +- It requires to build the client app first, after following its set-up [instructions](#client): + ``` + cd client + npm run build + ``` +- The built client app will be viewable on `http://localhost:3001` if the server is running. + @ciatph 20220406 diff --git a/package.json b/package.json index 332c5ba..7ca3ad8 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "1.0.0", "description": "API for Firebase Authentication users management using the firebase-admin SDK.", "main": "index.js", + "engines": { + "node": "14.x" + }, "scripts": { "install": "cd server && npm install", "build": "cd server && npm run build", diff --git a/server/package.json b/server/package.json index c5534c0..9aa745e 100644 --- a/server/package.json +++ b/server/package.json @@ -14,6 +14,7 @@ "seed": "node src/scripts/seeder.js", "lint": "eslint src --ignore-path .gitignore", "lint:fix": "eslint --ignore-path .gitignore --fix src", + "copyclient": "node src/scripts/copyclient.js", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { diff --git a/server/src/index.js b/server/src/index.js index 4118d6a..1982082 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -18,8 +18,8 @@ app.use(cors({ app.use('/api', controllers) -app.get('/', (req, res) => { - res.status(200).send('OK!') +app.get('*', (req, res) => { + res.sendFile(path.resolve(__dirname, 'public', 'index.html')) }) app.listen(PORT, () => { diff --git a/server/src/scripts/copyclient.js b/server/src/scripts/copyclient.js new file mode 100644 index 0000000..cbcadde --- /dev/null +++ b/server/src/scripts/copyclient.js @@ -0,0 +1,15 @@ +const fs = require('fs-extra') +const path = require('path') + +// Copy the /client build (website) directory to the server's public root directory +const copyClientApp = async (src, dest) => { + fs.move(src, dest, { overwrite: true }) + .then(() => console.log('success!')) + .catch(err => console.log(err.message)) +} + +(async () => { + const source = path.resolve(__dirname, '..', '..', '..', 'client', 'build') + const destination = path.resolve(__dirname, '..', 'public') + await copyClientApp(source, destination) +})()