简体   繁体   English

如何将Ember.js与Express.js集成?

[英]How to integrate Ember.js with Express.js?

I haven't seen an up-to-date question like this one, so here we go. 我还没有看到像这样的最新问题,所以我们走了。

How would I go about integrating an Ember.js frontend with an Express.js backend? 我如何将Ember.js前端与Express.js后端集成? I have an Express app exposing a RESTful API that I'd like to use Ember as a frontend for. 我有一个暴露RESTful API的Express应用程序,我想使用Ember作为前端。 Is there an example repo or something to help me get started? 有一个例子回购或什么来帮助我开始?

Edit: I thought you wanted to serve your app with your Express server. 编辑:我以为你想用Express服务器提供你的应用程序。 You just want to know how to use a rest api with Ember? 你只想知道如何使用Ember的rest api?

Definitely check out the RESTAdapter or JSONAPIAdapter 绝对检查RESTAdapter或JSONAPIAdapter

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
  namespace: 'api',
  host: 'https://express server here'
});

You should be able to serve the built version of your app with Express the way you normally would 您应该能够以通常的方式使用Express来提供应用程序的内置版本

ember build --environment=production

As @GJK pointed out, this isn't necessary for serving your app, but for a production build you would want to do this and serve out of the dist directory 正如@GJK指出的那样,这对于服务你的应用程序来说不是必需的,但是对于生产版本,你可能希望这样做并在dist目录中提供服务

I had an issue serving all of the routes and found this conversation helpful: Rewrite rule 我在为所有路线提供服务时遇到了问题,并发现此对话很有用: 重写规则

Unfortunately I dont have a repo to point you to but hopefully that helps 不幸的是,我没有一个回购指向你,但希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM