Open arthurmmedeiros opened 4 years ago
What I've done to get this working so far:
cert.pem
and key.pem
files in the private
folder of the solutionpackage.json
watch script to "watch": "concurrently --names 'API,UI' -c 'bgBlue,bgMagenta' \"npm run watch:api\" \"npm run watch:ui\"",
const fs = require('fs');
const chalk = require('chalk');
const express = require('express');
const cors = require('cors');
const path = require('path');
const https = require('https');
const bodyParser = require('body-parser');
const router = require('./router');
const Db = require('./db');
const NotificationManager = require('./utils/notification');
const TLS_KEY_PATH = path.join(dirname, '..', '..', 'private', 'key.pem'); const TLS_CERT_PATH = path.join(dirname, '..', '..', 'private', 'cert.pem');
function startAndListen(app, port) { return new Promise((resolve) => { app.listen(port, () => { resolve(); }); }) }
var corsOptions = { credentials: true, origin: function (origin, callback) { callback(null, true); } }
let httpsOptions = { key: fs.readFileSync(TLS_KEY_PATH), cert: fs.readFileSync(TLS_CERT_PATH) };
class ApiServer { constructor() { this.db = new Db(); this.notifications = null; }
_startApi() { this.app = express(); this.app.disable('x-powered-by'); this.app.use(bodyParser.json()); this.app.use(cors(corsOptions)); this.app.use('/api', router(this)); this.app.use('/images', express.static(path.join(dirname, '..', 'images'))); this.app.use('/', express.static(path.join(dirname, '..', '..', 'dist'))); return startAndListen(https.createServer(httpsOptions, this.app), 3100); } start() { return this.db.start() .then(() => { this.notifications = new NotificationManager(this); }) .then(() => this._startApi()) .then(() => { process.stdout.write(chalk.magenta('💻 API has started on https://localhost:3100/api')); }); } }
let api = new ApiServer(); api.start();
Hi there, First of all I have to say that I am very excited to do this tutorial, but I got stuck in the first exercise =/
Turns out these guys were having the same issue I'm facing, but there was no answer for the issue https://github.com/mike-works/pwa-fundamentals/issues/47
After 3 hours trying to make it work I decided to open this thread.
So, I have all the packages and tools installed in my machine. By looking at that post above I figured I needed OpenSSL installed, and also Git Bash to run the commands (why??).
npm run watch:api
seems to be workinghowever,
npm run watch
returns me thisAny idea what be causing it? Again, this is the same error someones described in that other post, but there was no answer explaining how to solve it.
Would it be possible to have a tutorial showing how to set up the environment on windows?
Also... why using NPM and Yarn? Should we not be using only one of them?