【发布时间】:2020-08-02 08:23:02
【问题描述】:
我正在尝试使用 IISNODE 模块在 Windows IIS 中部署一个 nuxt js 应用程序。但是对于我的生活来说,它无法正常工作。
我在 repo 的根目录中创建了一个 server.js 文件,其中包含以下代码:
const express = require('express')
const {Nuxt} = require('nuxt')
const app = express()
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000
// Import and set Nuxt.js options
let config = require('./nuxt.config.js')
const nuxt = new Nuxt(config)
// Give Nuxt middleware to express
app.use(nuxt.render)
// Listen the server
app.listen(port, host);
console.log('Server listening on ' + host + ':' + port);
然后我在 IIS 中配置了一个 web.config 文件,代码如下:
<!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="app/server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="/*" />
<action type="Rewrite" url="app/server.js" />
</rule>
</rules>
</rewrite>
当我尝试运行应用程序时,我在 IISNode 中收到以下错误。
Application has thrown an uncaught exception and is terminated:
C:\inetpub\Web\frontend\app\nuxt.config.js:2
export default {
^^^^^^
SyntaxError: Unexpected token 'export'
at new Script (vm.js:88:7)
at createScript (vm.js:263:10)
at Object.runInThisContext (vm.js:311:10)
at wrapSafe (internal/modules/cjs/loader.js:1057:15)
at Module._compile (internal/modules/cjs/loader.js:1120:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
似乎不接受 nuxt.config.js 文件中的导出。
这是我的 nuxt.config.js
export default {
mode: 'universal',
server: {
port: 2001, // default: 3000
host: '0.0.0.0' // default: localhost
},
/*
** Headers of the page
*/
head: {
title: process.env.npm_package_name || '',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
],
script: [
{}
]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#fff' },
/*
** Global CSS
*/
css: [
],
/*
** Plugins to load before mounting the App
*/
plugins: [
],
/*
** Nuxt.js dev-modules
*/
buildModules: [
],
/*
** Nuxt.js modules
*/
modules: [
// Doc: https://bootstrap-vue.js.org
'bootstrap-vue/nuxt',
'@nuxtjs/axios',
'@nuxtjs/toast',
'@nuxtjs/auth'
],
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
}
},
toast: {
position: 'top-center',
duration: 1500,
singleton: false,
register: [ // Register custom toasts
{
name: 'my-error',
message: 'Oops...Something went wrong',
options: {
type: 'error'
}
}
]
},
axios: {
baseURL: 'http://backend.local/'
},
auth: {
strategies: {
local: {
endpoints: {
login: { url: 'users/authenticate', method: 'post', propertyName: 'token' },
user: { url: 'user', method: 'get', propertyName: 'authorizedData.user' },
logout: false
}
}
}
}
}
任何解决此问题的帮助将不胜感激。
谢谢
国际消费电子展
【问题讨论】:
-
我能够通过应用 Nuxt JS Express 模板并调整 IISNode Web.config 首选项来解决问题。
-
您能再解释一下吗?我有同样的问题,我无法解决。