【问题标题】:Is it possible to add app.get() in sails.js project?是否可以在sails.js 项目中添加 app.get() ?
【发布时间】:2020-01-20 09:28:28
【问题描述】:

我在当前项目中使用sails.js v1。我想添加这行代码:

   app.get('*', (req, res) => {   
         res.sendFile(path.join(__dirname, '../apply_frontend/FrontEnd/dist/apply-system/index.html')); 
   });

有人对此有想法吗?谢谢。

【问题讨论】:

  • 您应该有一个config/route.js 文件,您可以在其中按照here 指南添加/更新您的路线

标签: node.js express sails.js


【解决方案1】:

不,你不能在sails.js 中使用app.get(),因为sails.js 默认提供路由文件 配置文件夹。 (https://sailsjs.com/documentation/concepts/routes)

app.get() 仅适用于 express.js,因为我们正在使用 express 构造函数初始化 app 变量。为此,我们需要使用 express npm 模块,如果您使用的是sails.js,则不需要。

var express = require('express');
const app = express();
app.get(); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多