Node.js 错误:Can';在express.js应用程序中发送邮件后,不要设置邮件头

Node.js 错误:Can';在express.js应用程序中发送邮件后,不要设置邮件头,node.js,express,coffeescript,Node.js,Express,Coffeescript,我正在运行一个express.js应用程序,其中有一个返回json对象的路由 在我的控制器文件夹中,我有chapters.coffee文件,如下所示 # Return the chapters.json based on the language i18n = require "i18next" fs = require "fs" cldr = require "cldr" __ = require "underscore" exports.chapters = (req, res, err

我正在运行一个express.js应用程序,其中有一个返回json对象的路由

在我的控制器文件夹中,我有chapters.coffee文件,如下所示

# Return the chapters.json based on the language
i18n = require "i18next"
fs = require "fs"
cldr = require "cldr"
__ = require "underscore"

exports.chapters = (req, res, err) ->
    fs.readFile "./data/chapters.json", (err, chapterJSON) ->
        console.log("read file error", err) if err
        tzmChapters = JSON.parse chapterJSON
        try
            # ...
            lngCode = req.query.setLng.split("-")[0]
        catch e
            # fallback to user locale
            lngCode = i18n.lng().split("-")[1]
        allCountries = cldr.extractTerritoryDisplayNames(lngCode)
        tzmNetwork = []
        tzm = __.each tzmChapters, (value, index, list) ->
            locale = value.desc.LOCALES.split("-")[1]
            tzmNetwork.push({link:value.desc.WEBSITE,contact:value.desc.CONTACT,country: allCountries[locale]})
        res.json {tzmNetwork}
有关代码,请访问

为什么我尝试从其他站点访问chapters json文件,我得到:

XMLHttpRequest cannot load http://localhost:3000/chapters. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
我如何在我的代码中启用它?有没有更好的方法来实现这一点,因为我还在footer.blade文件中使用它,并且我在apps.coffee文件中也阅读了chapters.json文件

非常感谢您的建议。

请先阅读

然后为安装Express中间件

请参见此答案