Skip to content

Commit 941f3ed

Browse files
committed
fix deploy env
1 parent f1ecc8b commit 941f3ed

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

json-server/app.js

100644100755
+14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
const express = require('express');
22
const path = require('path');
3+
const jsonServer = require('json-server');
4+
const server = jsonServer.create();
5+
const router = jsonServer.router('db.json');
6+
const middlewares = jsonServer.defaults();
37

48
const app = express();
59

10+
app.use(middlewares);
11+
app.use(router);
12+
613
app.use(express.static(path.join(__dirname,"../dist/todoapp/"))); //Serve static files (front end app)
714

815
app.get('/*', function(req,res) {
916
res.sendFile(path.join(path.join(__dirname,"../dist/todoapp/index.html")));
1017
});
1118

19+
// Avoid CORS issue
20+
server.use(function (req, res, next) {
21+
res.header("Access-Control-Allow-Origin", "*");
22+
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
23+
next();
24+
});
25+
1226
app.listen(process.env.PORT || 8080);

src/environments/environment.prod.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const environment = {
22
production: true,
3-
serverUrl: 'https://arr-todo.herokuapp.com',
3+
serverUrl: process.env.NODE_ENV === 'production' ? `${window.location.origin}/` : 'http://localhost:8080',
44
firebase: {
55
apiKey: 'AIzaSyBx-clRxjAtjniw1bxBG_p7-4DtnhKQX6g',
66
authDomain: 'todos-angular-app.firebaseapp.com',
@@ -11,3 +11,14 @@ export const environment = {
1111
appId: '1:676540201517:web:5792196cf1eb157b98d6a4'
1212
}
1313
};
14+
15+
16+
// export const baseUrl = 'http://localhost:3001/';
17+
18+
const url = (process.env.NODE_ENV === "production") ?
19+
`${window.location.origin}/`
20+
:
21+
'http://localhost:3001/' ;
22+
23+
console.log(url);
24+
export const baseUrl = url;

src/environments/environment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
export const environment = {
66
production: false,
7-
serverUrl: 'http://localhost:3000',
7+
serverUrl: 'http://localhost:8080',
88
firebase: {
99
apiKey: 'AIzaSyBx-clRxjAtjniw1bxBG_p7-4DtnhKQX6g',
1010
authDomain: 'todos-angular-app.firebaseapp.com',

0 commit comments

Comments
 (0)