我正在将应用程序部署到heroku,我按照他们在其文档中的部署指示进行了所有步骤,当我运行该应用程序时,在浏览器中出现以下错误:
<img src="//unsplash.it/400/300" class="overlay-pattern">
这是我的服务器
Invalid End point
这是我的服务。
const express = require('express');
const path = require('path');
const flash = require('connect-flash');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const db = require('./app/config/database');
// Connect To Database
mongoose.connect(db.database);
// On Connection
mongoose.connection.on('connected', () => {
console.log('Connected to database '+db.database);
});
// On Error
mongoose.connection.on('error', (err) => {
console.log('Database error: '+err);
});
const app = express();
const movies = require('./app/routes/movies');
// Port Number
const port = process.env.PORT || 8000
// CORS Middleware
app.use(cors());
// Set Static Folder
app.use(express.static(path.join(__dirname, 'movies-client')));
// Body Parser Middleware
app.use(bodyParser.json());
app.use('/movies', movies);
// Index Route
app.get('/', (req, res) => {
res.send('Invalid Endpoint');
});
// Start Server
app.listen(port, () => {
console.log('Server started on port '+port);
});
这是我的私人api网址:
import { Injectable } from '@angular/core';
import { Headers, Http, Response } from '@angular/http';
import { Jsonp } from '@angular/http';
@Injectable({
providedIn: 'root'
})
export class MoviesService {
queryUrl = '/search/';
// private apiUrl = '/movies';
constructor(private http: Http, private _jsonp: Jsonp) { }
getMovies(id: string): Promise<any> {
return this.http.get('movies/movies')
.toPromise()
.then(this.handleData)
.catch(this.handleError);
}
getMovie(id: string): Promise<any> {
return this.http.get('movies/movies' + id)
.toPromise()
.then(this.handleData)
.catch(this.handleError);
}
addReview(author, description) {
const uri = 'movies/comments';
const obj = {
author: author,
description: description
};
this
.http
.post(uri, obj)
.subscribe(res =>
console.log('Done'));
}
getReview(id: string): Promise<any> {
return this.http.get('movies/movies' + id)
.toPromise()
.then(this.handleData)
.catch(this.handleError);
}
searchMovies(searchStr: string): Promise<any> {
return this.http.get('movies/search' + this.queryUrl + searchStr)
.toPromise()
.then(this.handleData)
.catch(this.handleError);
}
getInTheaters(): Promise<any> {
return this.http.get('movies/theatre')
.toPromise()
.then(this.handleData)
.catch(this.handleError);
}
createMovie(movie: string): Promise<any> {
return this.http.post('movies/movies', movie)
.toPromise()
.then(this.handleData)
.catch(this.handleError);
}
private handleData(res: any) {
const body = res.json();
console.log(body); // for development purposes only
return body.result || body || {};
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error); // for development purposes only
return Promise.reject(error.message || error);
}
}
示例:如果我运行 private apiUrl = 'http://localhost:8000/movies';
我获得了所有电影,仅供参考:
我的代码端点有什么问题?我需要改变什么?任何帮助都会有所帮助,
答案 0 :(得分:0)
Hii将此添加到您的服务器代码中:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label><input value="Blue XL" type="checkbox" /> Blue XL</label>
<label><input value="Red Large" type="checkbox" /> Red Large</label>
<label><input value="Orange Medium" type="checkbox" /> Orange Medium</label>
<label><input value="Green Small" type="checkbox" /> Green Small</label>